leetcode算法
古波波
这个作者很懒,什么都没留下…
展开
-
Best Time to Buy and Sell Stock IV
Description: 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 complete at most k transactions. Note: Yo原创 2016-01-03 16:36:54 · 206 阅读 · 0 评论 -
Best Time to Buy and Sell Stock with Cooldown
来源:http://segmentfault.com/a/1190000004193861因为当前日期买卖股票会受到之前日期买卖股票行为的影响,首先考虑到用DP解决。这道题比较麻烦的是有个cooldown的限制,其实本质也就是买与卖之间的限制。对于某一天,股票有三种状态: buy, sell, cooldown, sell与cooldown我们可以合并成一种状态,因为手原创 2016-01-03 21:22:04 · 284 阅读 · 0 评论 -
295. Find Median from Data Stream
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median原创 2016-01-04 19:38:28 · 231 阅读 · 0 评论 -
68. Text Justification
解题思路这是一个典型的分治算法,基本思路就是:扫描字符串数组,累加长度,当发现长度超过最大长度的时候,就把前面的几个字符串按规则组合,加入到List中。public List<String> fullJustify(String[] words, int maxWidth) { List<String> result = new ArrayList<>(); if(w原创 2016-10-05 10:21:03 · 219 阅读 · 0 评论