LeetCode
文章平均质量分 68
离丶殇
这个作者很懒,什么都没留下…
展开
-
Regular Expression Matching
一. Regular Expression MatchingImplement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should原创 2017-03-23 19:23:59 · 176 阅读 · 0 评论 -
Multiply Strings
一. Multiply StringsGiven two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note:The length of both num1 and num2 is < 110.Both num1 and num2 contains原创 2017-04-05 13:45:04 · 174 阅读 · 0 评论 -
Permutation Sequence
一. Permutation SequenceThe set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): “12原创 2017-04-13 19:55:47 · 231 阅读 · 0 评论 -
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. For example, Given [0,原创 2017-04-04 21:50:31 · 159 阅读 · 0 评论 -
Insert Interval
一. Insert IntervalGiven a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their star原创 2017-04-13 12:35:29 · 221 阅读 · 0 评论 -
Spiral Matrix
一. Spiral MatrixGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ],原创 2017-04-09 19:07:39 · 209 阅读 · 0 评论 -
First Missing Positive
一. First Missing PositiveGiven an unsorted integer array, find the first missing positive integer.For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2.Your algorithm should run in O(n) ti原创 2017-04-03 20:45:14 · 174 阅读 · 0 评论 -
Sudoku Solver
一. Sudoku SolverWrite a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character ‘.’.You may assume that there will be only one unique solution.A sudoku pu原创 2017-04-03 18:35:28 · 271 阅读 · 0 评论 -
Increasing Subsequences
一. Increasing SubsequencesGiven an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at le原创 2017-03-15 23:39:14 · 249 阅读 · 0 评论 -
Longest Increasing Subsequence
一. Longest Increasing SubsequenceGiven an unsorted array of integers, find the length of longest increasing subsequence.For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subs原创 2017-03-17 00:23:20 · 221 阅读 · 0 评论 -
4Sum
一. 4SumGiven an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution原创 2017-03-26 18:58:40 · 169 阅读 · 0 评论 -
3Sum Closest
一. 3Sum ClosestGiven an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input woul原创 2017-03-24 22:07:37 · 152 阅读 · 0 评论 -
Wildcard Matching
一. Wildcard MatchingImplement wildcard pattern matching with support for ‘?’ and ‘*’.‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence).The matchin原创 2017-04-05 18:39:40 · 152 阅读 · 0 评论 -
Valid Number
一. Valid NumberValidate if a given string is numeric.Some examples: “0” => true ” 0.1 ” => true “abc” => false “1 a” => false “2e10” => trueNote: It is intended for the problem statement原创 2017-04-15 15:04:51 · 255 阅读 · 0 评论 -
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).For example, S = “ADOBECODEBANC” T = “ABC”原创 2017-04-19 15:29:20 · 189 阅读 · 0 评论 -
Unique Binary Search Trees
一. Unique Binary Search TreesGiven n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example, Given n = 3, there are a total of 5 unique BST’s. 1 3原创 2017-05-10 16:57:20 · 264 阅读 · 0 评论 -
Gray Code
一. Gray CodeThe gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the seque原创 2017-04-26 16:27:47 · 200 阅读 · 0 评论 -
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”: great /原创 2017-04-26 16:00:06 · 259 阅读 · 0 评论 -
Maximal Rectangle
一. Maximal RectangleGiven a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.For example, given the following matrix: 1 0 1 0 0 1 0 1 1原创 2017-04-25 14:43:06 · 251 阅读 · 0 评论 -
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.Above is a h原创 2017-04-24 16:22:09 · 251 阅读 · 0 评论 -
Edit Distance
一. Edit DistanceGiven two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted原创 2017-04-17 14:12:28 · 284 阅读 · 0 评论 -
二叉查找树
一、LeetCodeMediumUnique Binary Search TreesUnique Binary Search Trees II【TIMEOUT】Validate Binary Search TreeHardRecover Binary Search Tree【TIMEOUT】原创 2017-05-10 19:15:56 · 243 阅读 · 0 评论 -
Recover Binary Search Tree
一. Recover Binary Search TreeTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note: A solution using O(n) space is pretty straight forw原创 2017-05-10 19:10:08 · 304 阅读 · 0 评论 -
Validate Binary Search Tree
一. Validate Binary Search TreeGiven a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less原创 2017-05-10 18:58:19 · 256 阅读 · 0 评论 -
Permutations II
一. Permutations IIGiven a collection of numbers that might contain duplicates, return all possible unique permutations.For example, [1,1,2] have the following unique permutations: [ [1,1,2],原创 2017-04-06 19:31:21 · 143 阅读 · 0 评论 -
Jump Game II
一. Jump Game IIGiven 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原创 2017-04-06 18:53:52 · 167 阅读 · 0 评论 -
3Sum
一. 3SumGiven an array S of n integers, are there elements a, b, c in S 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 contain原创 2017-03-24 21:52:48 · 198 阅读 · 0 评论 -
Longest Valid Parentheses
一. Longest Valid ParenthesesGiven a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses原创 2017-03-31 20:50:46 · 218 阅读 · 0 评论 -
Longest Common Prefix
一. Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.Difficulty:EasyTIME:16MIN解法在很多的字符串中寻找这些字符串的最长公共前缀。当然没什么难度,我这里使用了一个prefix作为当前找到的最长公共前缀,然后依次匹原创 2017-03-24 16:15:48 · 135 阅读 · 0 评论 -
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原创 2017-04-08 12:24:19 · 216 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
一. Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters.Examples: Given “abcabcbb”, the answer is “abc”, which the length原创 2017-03-12 23:56:20 · 169 阅读 · 0 评论 -
Two Sum
一. Two SumGiven 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原创 2017-03-13 00:07:01 · 229 阅读 · 0 评论 -
Merge k Sorted Lists
一. Merge k Sorted ListsMerge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Difficulty:HardTIME:16MIN解法一我们都知道合并两个有序的列表,时间复杂度为O(n)O(n),但如果是合并k个列表呢?最简单的做法当然是每原创 2017-03-28 19:59:20 · 186 阅读 · 0 评论 -
String to Integer (atoi)
一. String to Integer (atoi)Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are原创 2017-03-21 20:57:09 · 259 阅读 · 0 评论 -
Wiggle Subsequence
一. Wiggle SubsequenceA sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exist原创 2017-03-21 17:03:12 · 202 阅读 · 0 评论 -
Distinct Subsequences
一. Distinct SubsequencesGiven a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleti原创 2017-03-20 20:20:16 · 277 阅读 · 0 评论 -
Increasing Triplet Subsequence
一. Increasing Triplet SubsequenceGiven an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should: Return true if there exists i, j,原创 2017-03-17 22:23:33 · 145 阅读 · 0 评论 -
Reverse Nodes in k-Group
一. Reverse Nodes in k-GroupGiven a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked原创 2017-03-29 22:20:08 · 160 阅读 · 0 评论 -
Divide Two Integers
一. Divide Two IntegersDivide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.Difficulty:MediumTIME:TIMEOUT解法实现整数的除法,不能用乘法除法以及取余。因此就剩下加减法,用加减法当然可以,原创 2017-03-30 00:26:00 · 306 阅读 · 0 评论 -
Pow(x, n)
一. Pow(x, n)Implement pow(x, n).Difficulty:MediumTIME:20MIN解法一(递归)这道题是求某个数的n次幂,按我们正常的思维来说,可能就是求n次乘法算得结果,时间复杂度为O(n)O(n)。假设是求x8x^8,我们可以分解为8个xx相乘,同样,我们也可以分解为((x2)2)2((x^2)^2)^2,但这个时候,我们就只需要三次乘法。因此,快速幂的要诀就原创 2017-04-08 14:04:10 · 244 阅读 · 0 评论