
【LeetCode】刷题记录
ccq1n
TongjiU 2022级大三
展开
-
【LeetCode】1. Two Sum(Hash Table)
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same ...原创 2018-10-16 22:06:21 · 240 阅读 · 0 评论 -
31. Next Permutation【下一个排列】
Implementnext permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible o...原创 2019-01-24 16:46:11 · 207 阅读 · 0 评论 -
【Leetcode】38. Count and Say
38.Count and SayThe count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211is read off as"one 1"or...原创 2019-03-12 10:28:47 · 102 阅读 · 0 评论 -
【Leetcode】39. Combination Sum
Given asetof candidate numbers (candidates)(without duplicates)and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Thesamerepeat...原创 2019-03-12 14:12:44 · 98 阅读 · 0 评论 -
49. Group Anagrams【Python字典操作】
Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat"原创 2019-03-16 20:58:29 · 457 阅读 · 0 评论 -
【Leetcode】53. Maximum Subarray(最大子串之和)
Given an integer arraynums, find the contiguous subarray(containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanati...原创 2019-03-20 20:15:17 · 177 阅读 · 0 评论 -
【Leetcode】50. Pow(x, n) 快速幂
Implementpow(x,n), which calculatesxraised to the powern(xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000, ...原创 2019-03-17 18:14:39 · 149 阅读 · 0 评论 -
【Leetcode】40. Combination Sum II
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Each number incandidatesmay...原创 2019-03-12 20:00:02 · 120 阅读 · 0 评论 -
【Leetcode】62. Unique Paths(动态规划)
A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo...原创 2019-03-22 10:32:03 · 120 阅读 · 0 评论 -
【Leetcode】42. Trapping Rain Water
Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.The above elevation map is represented by array...原创 2019-03-13 20:12:08 · 97 阅读 · 0 评论 -
【Leetcode】51. N-Queens (搜索)
Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinct solutions to then-queens puzzle.Eac...原创 2019-03-18 21:25:09 · 90 阅读 · 0 评论 -
【Leetcode】68. Text Justification
Given an array of words and a widthmaxWidth, format the text such that each line has exactlymaxWidthcharacters and is fully (left and right) justified.You should pack your words in a greedy appro...原创 2019-03-29 14:45:49 · 99 阅读 · 0 评论 -
【Leetcode】54. Spiral Matrix(模拟)
Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.Example 1:Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5]...原创 2019-03-22 20:39:20 · 105 阅读 · 0 评论 -
【Leetcode】69. Sqrt(x)(二分搜索)
Implementint sqrt(int x).Compute and return the square root ofx, wherexis guaranteed to be a non-negative integer.Since the return typeis an integer, the decimal digits are truncated and only...原创 2019-03-29 20:15:35 · 123 阅读 · 0 评论 -
【Leetcode】55. Jump Game(模拟)
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if yo...原创 2019-03-23 13:56:26 · 81 阅读 · 0 评论 -
【Leetcode】60. Permutation Sequence
The set[1,2,3,...,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order, we get the following sequence forn= 3:"123" "132" "213" "231" "312"...原创 2019-03-26 18:10:06 · 96 阅读 · 0 评论 -
【Leetcode】56. Merge Intervals(模拟)
Given a collection of intervals, merge all overlapping intervals.Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps...原创 2019-03-23 19:57:03 · 108 阅读 · 0 评论 -
【Leetcode】70. Climbing Stairs(动态规划)
You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note:Givennwill be a positive...原创 2019-03-30 21:19:32 · 151 阅读 · 0 评论 -
【Leetcode】61. Rotate List(链表)
Given a linkedlist, rotate the list to the right bykplaces, wherekis non-negative.Example 1:Input: 1->2->3->4->5->NULL, k = 2Output: 4->5->1->2->3->NULLExplana...原创 2019-03-26 19:14:51 · 119 阅读 · 0 评论 -
【Leetcode】45. Jump Game II(动态规划)
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to...原创 2019-03-31 14:28:58 · 460 阅读 · 0 评论 -
【Leetcode】79. Word Search(DFS)
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically n...原创 2019-04-04 19:55:37 · 126 阅读 · 0 评论 -
【Leetcode】57. Insert Interval(模拟)
Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Examp...原创 2019-03-24 15:45:09 · 100 阅读 · 0 评论 -
【Leetcode】63. Unique Paths II(动态规划)
A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo...原创 2019-03-27 14:42:39 · 129 阅读 · 0 评论 -
【Leetcode】64. Minimum Path Sum(动态规划)
Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or right at a...原创 2019-03-27 20:02:49 · 181 阅读 · 0 评论 -
【Leetcode】82. Remove Duplicates from Sorted List II(链表)
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.Example 1:Input: 1->2->3->3->4->4->5Output: 1->...原创 2019-04-06 16:27:14 · 118 阅读 · 0 评论 -
【Leetcode】83. Remove Duplicates from Sorted List(链表)
Given a sorted linked list, delete all duplicates such that each element appear onlyonce.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Output: 1-...原创 2019-04-06 19:31:45 · 101 阅读 · 0 评论 -
【Leetcode】93. Restore IP Addresses(模拟)(2019年美团无人驾驶算法实习面试原题)
Given a string containing only digits, restore it by returning all possible valid IP address combinations.Example:Input: "25525511135"Output: ["255.255.11.135", "255.255.111.35"]题目大意:给出一个st...原创 2019-04-10 20:19:22 · 199 阅读 · 0 评论 -
【Leetcode】72. Edit Distance(动态规划)(2019拼多多笔试)(重点)
Given two wordsword1andword2, find the minimum number of operations required to convertword1toword2.You have the following 3 operations permitted on a word:Insert a character Delete a chara...原创 2019-04-01 20:08:42 · 275 阅读 · 0 评论 -
【Leetcode】66. Plus One
Given anon-emptyarray of digitsrepresenting a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each element...原创 2019-03-28 13:51:30 · 103 阅读 · 0 评论 -
【Leetcode】84. Largest Rectangle in Histogram(思维)(重点关注)
Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of ea...原创 2019-04-07 15:45:34 · 232 阅读 · 0 评论 -
【Leetcode】85. Maximal Rectangle(求最大矩形)(动态规划)
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.Example:Input:[ ["1","0","1","0","0"], ["1","0","1","1","1"], ["1","1",...原创 2019-04-07 20:24:44 · 901 阅读 · 0 评论 -
【Leetcode】67. Add Binary
Given two binary strings, return their sum (also a binary string).The input strings are bothnon-emptyand contains only characters1or0.Example 1:Input: a = "11", b = "1"Output: "100"Exam...原创 2019-03-28 18:55:35 · 91 阅读 · 0 评论 -
【Leetcode】86. Partition List
Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each of th...原创 2019-04-08 10:32:51 · 106 阅读 · 0 评论 -
【Leetcode】94. Binary Tree Inorder Traversal(二叉树中序遍历)
Given a binary tree, return theinordertraversal of its nodes' values.Example:Input: [1,null,2,3] 1 \ 2 / 3Output: [1,3,2]题目大意:二叉树中序遍历。解题思路:按照左输出右的递归即可。/** * ...原创 2019-04-11 19:25:31 · 118 阅读 · 0 评论 -
【Leetcode】87. Scramble String(DFS)(字符串)
Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ofs1="great": great / \ gr ...原创 2019-04-08 15:03:17 · 197 阅读 · 0 评论 -
【Leetcode】88. Merge Sorted Array
Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:The number of elements initialized innums1andnums2aremandnrespectively. You may assume that...原创 2019-04-08 19:52:01 · 128 阅读 · 0 评论 -
【Leetcode】89. Gray Code(规律)(二进制相邻位变换)
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gr...原创 2019-04-09 10:30:14 · 363 阅读 · 0 评论 -
【Leetcode】102. Binary Tree Level Order Traversal
Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree[3,9,20,null,null,15,7], 3 / \ 9 20 ...原创 2019-04-15 19:56:47 · 130 阅读 · 0 评论 -
【Leetcode】95. Unique Binary Search Trees II(二叉树生成)(搜索思想)
Given an integern, generate all structurally uniqueBST's(binary search trees) that store values 1 ...n.Example:Input: 3Output:[ [1,null,3,2], [3,2,null,1], [3,1,null,null,2], [2,1,3...原创 2019-04-12 19:36:18 · 145 阅读 · 0 评论 -
【Leetcode】90. Subsets II(思维)(重复数据的子集)(划重点)
Given a collection of integers that might contain duplicates,nums, return all possible subsets (the power set).Note:The solution set must not contain duplicate subsets.Example:Input: [1,2,2]...原创 2019-04-09 20:29:29 · 143 阅读 · 0 评论