
贪心
markpen
这个作者很懒,什么都没留下…
展开
-
Leetcode Best Time to Buy and Sell Stock
题意:给出股票价格,求出买入卖出后的最大收益。思路:贪心。找到每一天前的最低股价。class Solution {public: int maxProfit(vector& prices) { int profit = 0; int minprice = 999999; for(int i = 0; i < prices.size(原创 2016-12-18 08:34:17 · 170 阅读 · 0 评论 -
Leetcode Container With Most Water
题意:找到蓄水量最大的容器。思路:从两边开始找,每次更新较小的边。class Solution {public: int maxArea(vector& height) { int low = 0; int high = height.size() - 1; int maxwater = 0; while(low <原创 2016-12-19 14:08:24 · 171 阅读 · 0 评论