随笔分类 -  LeetCode

1 2 下一页
LeetCode切题笔记
LeetCode 334 Increasing Triplet
摘要:这个题是说看一个没有排序的数组里面有没有三个递增的子序列,也即: Return true if there exists i, j, k such that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false. 大 阅读全文
posted @ 2016-02-28 19:46 lichen782 阅读(603) 评论(0) 推荐(0) 编辑
LeetCode 笔记27 Two Sum III - Data structure design
摘要:Design and implement a TwoSum class. It should support the following operations:addandfind.add- Add the number to an internal data structure.find- Fin... 阅读全文
posted @ 2015-03-18 20:34 lichen782 阅读(573) 评论(0) 推荐(0) 编辑
LeetCode 笔记28 Maximum Gap
摘要:Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 ... 阅读全文
posted @ 2015-03-11 22:19 lichen782 阅读(301) 评论(0) 推荐(0) 编辑
LeetCode 笔记26 Maximum Product Subarray
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array[2,3,-2,4],the... 阅读全文
posted @ 2015-03-08 20:16 lichen782 阅读(285) 评论(0) 推荐(0) 编辑
LeetCode 笔记26 Single Number II
摘要:Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime comp... 阅读全文
posted @ 2015-02-27 21:29 lichen782 阅读(1986) 评论(0) 推荐(0) 编辑
LeetCode 笔记25 Candy (艰难的调试)
摘要:There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requi... 阅读全文
posted @ 2015-02-25 22:12 lichen782 阅读(355) 评论(0) 推荐(0) 编辑
LeetCode 笔记24 Palindrome Partitioning II (智商碾压)
摘要:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs... 阅读全文
posted @ 2015-02-24 13:06 lichen782 阅读(361) 评论(0) 推荐(0) 编辑
LeetCode 笔记23 Best Time to Buy and Sell Stock III
摘要:Best Time to Buy and Sell Stock IIISay you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the... 阅读全文
posted @ 2015-02-18 10:24 lichen782 阅读(377) 评论(0) 推荐(0) 编辑
LeetCode 笔记22 Distinct Subsequences 动态规划需要冷静
摘要:Distinct SubsequencesGiven a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is... 阅读全文
posted @ 2015-02-16 20:40 lichen782 阅读(472) 评论(0) 推荐(0) 编辑
LeetCode 笔记21 生成第k个排列
摘要:题目是这样的: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 seque... 阅读全文
posted @ 2015-02-01 10:38 lichen782 阅读(558) 评论(0) 推荐(0) 编辑
LeetCode 笔记系列 20 Interleaving String [动态规划的抽象]
摘要:题目:Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="aadbbbaccc", return false.这个题目值得记录的原因除了自己的解法没有通过大集合以外,主要还在与对动态规划的理解。在这两个月研究算法的过程中,我发现自己更倾向于直观的理解,而抽象思维上相对较弱 阅读全文
posted @ 2013-07-24 12:06 lichen782 阅读(5259) 评论(1) 推荐(1) 编辑
LeetCode 笔记系列 19 Scramble String [合理使用递归]
摘要:题目: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 eat / \ / \g r e at / \ a tTo scramble the string, we may choose any non-leaf... 阅读全文
posted @ 2013-07-21 17:18 lichen782 阅读(1962) 评论(1) 推荐(0) 编辑
LeetCode 笔记系列 18 Maximal Rectangle [学以致用]
摘要:题目:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.leetcode的题目真是越来越经典了。比如这个题目,就是一道男默女泪的题。一般人拿到这个题目,除非做过类似的,很难一眼找出一个方法来,更别说找一个比较优化的方法了。首先一个难点就是,你怎么判断某个区域就是一个矩形呢?其次,以何种方式来遍历这个2D的matrix呢?一般来说,对这种“棋盘式”的题目,像什么Queen啦,象棋啦,数独啦,如果没有 阅读全文
posted @ 2013-07-20 23:17 lichen782 阅读(23505) 评论(7) 推荐(3) 编辑
LeetCode 笔记系列 17 Largest Rectangle in Histogram
摘要:题目:Largest Rectangle in HistogramGivennnon-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 each bar is 1, given height =[2,1,5,6,2,3].The largest rectangle is shown 阅读全文
posted @ 2013-07-17 21:51 lichen782 阅读(29770) 评论(24) 推荐(10) 编辑
LeetCode 笔记系列16.3 Minimum Window Substring [从O(N*M), O(NlogM)到O(N),人生就是一场不停的战斗]
摘要:题目:Given 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"Minimum window is"BANC".Note:If there is no such window in S that covers all characters in T, return the em 阅读全文
posted @ 2013-07-16 18:45 lichen782 阅读(5315) 评论(1) 推荐(4) 编辑
LeetCode 笔记系列16.2 Minimum Window Substring [从O(N*M), O(NlogM)到O(N),人生就是一场不停的战斗]
摘要:题目:Given 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"Minimum window is"BANC".Note:If there is no such window in S that covers all characters in T, return the em 阅读全文
posted @ 2013-07-16 17:14 lichen782 阅读(861) 评论(0) 推荐(0) 编辑
LeetCode 笔记系列16.1 Minimum Window Substring [从O(N*M), O(NlogM)到O(N),人生就是一场不停的战斗]
摘要:题目:Given 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" Minimum window is"BANC". Note: If there is no such window in S that covers all characters in T, return 阅读全文
posted @ 2013-07-16 16:48 lichen782 阅读(1243) 评论(0) 推荐(0) 编辑
LeetCode 笔记系列15 Set Matrix Zeroes [稍微有一点hack]
摘要:题目:Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m+n) space, but still not the best solution.Could you devise a constant space 阅读全文
posted @ 2013-07-14 22:04 lichen782 阅读(697) 评论(0) 推荐(0) 编辑
LeetCode 笔记系列 14 N-Queen II [思考的深度问题]
摘要:题目:Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions.就是让你输出N皇后问题的解法数目。直接求解,每次还记录整个棋盘位置那种方法就不说了,必须超时。有一个牛逼大了的超级无敌帅的位移动解法。我们暂且不表。看看我当时想的一个解法。首先,对于皇后的那个递归方法,我有三个变量分别表示1.一个int值,表示递归到当前的level,当前的哪几个col被占领了,例如11011就表示我们下一个Q只能放在第三个(. 阅读全文
posted @ 2013-07-12 20:22 lichen782 阅读(2810) 评论(1) 推荐(0) 编辑
LeetCode 笔记系列13 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 reach the last index in the minimum number of jumps.For example:Given array A =[2,3,1,1,4]The minim 阅读全文
posted @ 2013-07-10 23:13 lichen782 阅读(16811) 评论(4) 推荐(0) 编辑

1 2 下一页