2013年7月20日
摘要: 题目: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 阅读(23507) 评论(7) 推荐(3) 编辑
  2013年7月17日
摘要: 题目: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 阅读(29781) 评论(24) 推荐(11) 编辑
  2013年7月16日
摘要: 题目: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 阅读(5316) 评论(1) 推荐(4) 编辑
摘要: 题目: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) 编辑
摘要: 题目: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 阅读(1245) 评论(0) 推荐(0) 编辑
  2013年7月14日
摘要: 题目: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 阅读(698) 评论(0) 推荐(0) 编辑
  2013年7月12日
摘要: 题目: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 阅读(2811) 评论(1) 推荐(0) 编辑
  2013年7月10日
摘要: 题目: 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 阅读(16822) 评论(4) 推荐(0) 编辑
摘要: 题目: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. For example, Given[0,1,0,2,1,0,1,3,2,1,2,1], return6.例如给出上图中的黑色部分(数组表示),让你求出蓝色部分。这也是个神题。。。当然对小白我来说。想了半天,是不是遍历数组呢,然后依次计算当前bar构成的container大小。问题在于,这个.. 阅读全文
posted @ 2013-07-10 19:04 lichen782 阅读(1295) 评论(0) 推荐(0) 编辑
摘要: 题目:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should run inO(n) time and uses constant space.为什么这道题值得纪念呢? 因为它教育我们看问题看本质。要看出问题本质,首先要深刻理解问题本身是在说啥。。。(越来越像学习某某core的讲话了)在一个无序的整数数组中,找出第一个没有的正数。什么意思呢?这么想,所有正数是 阅读全文
posted @ 2013-07-10 10:08 lichen782 阅读(1089) 评论(0) 推荐(0) 编辑