2014年1月26日

LeetCode: 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.本来的想法就是最naive的想法。对应每一个bar,在它的左右两侧延伸,直到遇到一个比这个值小的bar,计算面积。可以通过,就是时间比较长。后来在网上看到一种O(n)的算法。。我发现很多我做出来的题都不是最优的算法,都是一些naive的算法。Actually, we can decr 阅读全文

posted @ 2014-01-26 23:47 longhorn 阅读(169) 评论(0) 推荐(0) 编辑

LeetCode: Container With Most Water

摘要: Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.最开始只能想到bru 阅读全文

posted @ 2014-01-26 07:47 longhorn 阅读(141) 评论(0) 推荐(0) 编辑

LeetCode: strStr

摘要: Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.我以为不就是找个字符串吗,扫描一遍不就行了。。后来才发现,原来面试的时候不让用这种方法,都考出花了。所以学习了一下KMP算法。具体内容有链接。 1 public static String kmp(String haystack, String needle) { 2 if (needle.length() == 0) return haystack; 3 ... 阅读全文

posted @ 2014-01-26 01:57 longhorn 阅读(189) 评论(0) 推荐(0) 编辑

导航