随笔分类 -  2 Leetcode

摘要:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpo... 阅读全文
posted @ 2014-10-16 21:56 Avril 阅读(410) 评论(0) 推荐(0)
摘要:There 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 req... 阅读全文
posted @ 2014-10-16 21:15 Avril 阅读(439) 评论(0) 推荐(0)
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.这题和sort list等题都比较相似,需要先用快慢指针的方法找到链表的中点,然后... 阅读全文
posted @ 2014-10-16 20:52 Avril 阅读(323) 评论(0) 推荐(0)
摘要:Say 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 complet... 阅读全文
posted @ 2014-10-16 20:14 Avril 阅读(388) 评论(0) 推荐(0)
摘要:Given 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.... 阅读全文
posted @ 2014-10-12 16:28 Avril 阅读(249) 评论(0) 推荐(0)
摘要:Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all ... 阅读全文
posted @ 2014-10-12 15:52 Avril 阅读(199) 评论(0) 推荐(0)
摘要: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 @ 2014-10-12 14:54 Avril 阅读(470) 评论(0) 推荐(0)
摘要:参考:http://www.cppblog.com/wicbnu/archive/2013/03/18/198565.html我太喜欢用dfs和回溯法了,但是这些暴力的方法加上剪枝之后复杂度依然是很高,显然不能达到题目的要求。这个时候应该考虑动态规划,并且要复杂度尽量接近O(n^2)的算法。下面这个... 阅读全文
posted @ 2013-08-31 20:15 Avril 阅读(3355) 评论(1) 推荐(0)
摘要:Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region... 阅读全文
posted @ 2013-08-30 19:15 Avril 阅读(1853) 评论(0) 推荐(0)
摘要:http://blog.csdn.net/abcbc/article/details/8943485具体的题目描述为:Givennnon-negative integers representing the histogram's bar height where the width of each... 阅读全文
posted @ 2013-08-24 01:21 Avril 阅读(8555) 评论(3) 推荐(1)