摘要: Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is[1, 2, 3, 4]. Return its length:4.Your algorithm should run in O(n) complexity.[解题思路]数组,O(n)---->使用hash,空间换时间对于当前数N 阅读全文
posted @ 2013-08-17 21:44 feiling 阅读(362) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again). 1 public c 阅读全文
posted @ 2013-08-17 20:46 feiling 阅读(297) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at 阅读全文
posted @ 2013-08-17 15:45 feiling 阅读(210) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.[解题思路]记录一个最小值,每次拿当前值与最小值比较,如果两者差>profit,则更新profit 1 publ 阅读全文
posted @ 2013-08-17 15:12 feiling 阅读(253) 评论(0) 推荐(0) 编辑