摘要: 很简单,稍微观察一下就可以得出规律:每次买入之后在最高的时候卖出,只需用low和high来记录买入、卖出的价格,遇到更高价格的时候更新high,否则卖出,然后同时更新low和high。结束之后最后一次的收入=high - low不要忘了加进去! 1 class Solution { 2 public: 3 int maxProfit(vector &prices) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if... 阅读全文
posted @ 2013-08-31 22:33 Exio 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 可以转化成图的题目,bfs,代码可以写得很短! 1 class Solution { 2 public: 3 int ladderLength(string start, string end, unordered_set &dict) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 deque > nodes; 7 nodes.push_back(pair(start, 1)); 8 ... 阅读全文
posted @ 2013-08-31 21:58 Exio 阅读(169) 评论(0) 推荐(0) 编辑