- 博客(79)
- 收藏
- 关注
原创 [leetcode] 152. Maximum Product Subarray
Maximum Product SubarrayGiven an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output:...
2019-08-26 15:44:09
287
原创 [leetcode] 149. Max Points on a Line
Max Points on a LineGiven n points on a 2D plane, find the maximum number of points that lie on the same straight line.Example 1:Input: [[1,1],[2,2],[3,3]]Output: 3Explanation:^|| o| ...
2019-08-24 21:36:53
256
原创 [leetcode] 139. Word Break
Word BreakGiven a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.N...
2019-08-17 11:25:40
280
原创 [leetcode] 135. Candy
CandyThere are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on...
2019-08-16 21:40:49
201
原创 [leetcode] 132.Palindrome Partitioning II
Palindrome Partitioning IIGiven a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.Example:Input:...
2019-08-16 19:22:14
253
原创 [leetcode] 131. Palindrome Partitioning
Palindrome PartitioningGiven a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.Example:Input: “aab”Output:[[“a...
2019-08-16 16:48:42
203
原创 [leetcode] 130. Surrounded Regions
Surrounded RegionsGiven a 2D board containing ‘X’ and ‘O’ (the letter O), capture all regions surrounded by ‘X’.A region is captured by flipping all 'O’s into 'X’s in that surrounded region.Example...
2019-08-16 15:30:42
155
原创 [leetcode] 127. Word Ladder
Word LadderGiven two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be chan...
2019-08-14 22:19:40
158
原创 [leetcode] 128. Longest Consecutive Sequence
Longest Consecutive SequenceGiven an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input: [100, 4...
2019-08-12 21:56:05
174
原创 [leetcode] 115. Distinct Subsequences
Distinct SubsequencesGiven a string S and a string T, count the number of distinct subsequences of S which equals T.A subsequence of a string is a new string which is formed from the original string...
2019-08-10 10:09:09
201
原创 [leetcode] 97. Interleaving String
Interleaving StringGiven s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.Example 1:Input: s1 = “aabcc”, s2 = “dbbca”, s3 = “aadbbcbcac”Output: trueExample 2:Input: s1 =...
2019-08-01 20:02:54
278
原创 [leetcode] 87. Scramble String
Scramble StringGiven a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = “great”:Given two str...
2019-07-31 19:03:07
175
原创 [leetcode] 221. Maximal Square && 85. Maximal Rectangle
Maximal SquareGiven a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.Example:Input:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0Output: 4解法...
2019-07-28 13:18:36
347
原创 [LeetCode] 78. Subsets && 90. Subsets II
SubsetsGiven a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[[3],[...
2019-07-26 20:17:42
197
原创 [LeetCode] 93. Restore IP Addresses
Restore IP AddressesGiven 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.3...
2019-07-25 20:28:53
154
原创 [LeetCode] 84. Largest Rectangle in Histogram
Largest Rectangle in HistogramGiven n non-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.Example:I...
2019-07-23 16:34:35
163
原创 [leetcode] 76. Minimum Window Substring
Minimum Window SubstringGiven a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).Example:Input: S = “ADOBECODEBANC”, T = “ABC”Ou...
2019-07-21 15:09:25
183
原创 [LeetCode] 72. Edit Distance
Edit DistanceGiven two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert a characterDel...
2019-07-21 11:46:51
169
原创 [LeetCode] 123. Best Time to Buy and Sell Stock III
Best Time to Buy and Sell Stock IIISay you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two...
2019-04-06 15:59:46
199
原创 [LeetCode] 51. N-Queens
N-QueensThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle...
2019-04-02 16:15:46
229
原创 [LeetCode] 47. Permutations 2
Permutations 2Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[[1,1,2],[1,2,1],[2,1,1]]解析相比于Permutations,...
2019-04-02 15:02:52
237
原创 [LeetCode] 46. Permutations
PermutationsGiven a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]解析生成全排列。解法1:DFS用一个...
2019-04-01 16:39:43
202
原创 [LeetCode] 45. Jump Game2
Jump Game2Given 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 g...
2019-04-01 15:36:45
250
原创 [LeetCode] 55. Jump Game
Jump GameGiven 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.Determi...
2019-04-01 15:17:54
215
原创 [LeetCode] 43. Multiply Strings
Multiply StringsGiven two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.Example 1:Input: num1 = “2”, num2 = “3”Outp...
2019-03-31 23:07:12
189
原创 [LeetCode] 42. Trapping Rain Water
Trapping Rain WaterGiven n non-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.Example:Input: [0,1,0,2,1,...
2019-03-31 21:25:33
226
原创 [LeetCode] 41. First Missing Positive
First Missing PositiveGiven an unsorted integer array, find the smallest missing positive integer.Example 1:Input: [1,2,0]Output: 3Example 2:Input: [3,4,-1,1]Output: 2Example 3:Input: [7...
2019-03-30 17:58:29
188
原创 [LeetCode] 37. Sudoku Solver
Sudoku SolverWrite a program to solve a Sudoku puzzle by filling the empty cells.A sudoku solution must satisfy all of the following rules:Each of the digits 1-9 must occur exactly once in each ro...
2019-03-29 14:14:21
239
原创 [LeetCode] 34. Find First and Last Position of Element in Sorted Array Medium
Find First and Last Position of Element in Sorted ArrayGiven an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s runti...
2019-03-29 13:02:36
328
原创 [LeetCode] 33. Search in Rotated Sorted Array
Search in Rotated Sorted ArraySuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a targ...
2019-03-29 10:00:58
203
原创 [LeetCode] 32. Longest Valid Parentheses
Longest Valid ParenthesesGiven a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: “(()”Output: 2Explan...
2019-03-28 21:24:10
253
原创 [LeetCode] 29. Divide Two Integers
Divide Two IntegersGiven two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividing dividend by divisor.The in...
2019-03-28 19:03:12
184
原创 [LeetCode] 22. Generate Parentheses
Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[“((()))”,“(()())”,“(())()...
2019-03-27 17:16:21
186
原创 [LeetCode] 17. Letter Combinations of a Phone Number
Letter Combinations of a Phone NumberGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just ...
2019-03-27 15:44:43
325
原创 [LeetCode] 18. 4Sum
4SumGiven an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum o...
2019-03-27 10:28:36
204
原创 [LeetCode] 16. 3Sum Closest
3Sum ClosestGiven an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each...
2019-03-27 09:46:33
201
原创 [LeetCode] 15. 3Sum
3SumGiven an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not c...
2019-03-26 20:55:00
172
原创 [LeetCode] 10. Regular Expression Matching
Regular Expression MatchingGiven an input string (s) and a pattern §, implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character.‘*’ Matches zero or more o...
2019-03-25 21:51:33
193
原创 [LeetCode] 4. Median of Two Sorted Arrays
Median of Two Sorted ArraysThere are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n))....
2019-03-24 19:51:44
263
原创 [LeetCode] 3. Longest Substring Without Repeating Characters
Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters.Example 1:Input: “abcabcbb”Output: 3Explanation: The answer is...
2019-03-24 15:43:04
209
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅