LeetCode_Best Time to Buy and Sell Stock II
2013-04-10 23:18
507 查看
class Solution { public: int maxProfit(vector<int> &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function if( prices.size() < 2 ) return 0; int result = 0; int min = 0,i; for(i = 1; i< prices.size(); i++) { if(prices[i] >= prices[i-1]) continue; else{ result += prices[i-1] - prices[min]; min = i; } } if(prices[i-1] >prices[min]) result += prices[i-1] -prices[min]; return result; } };
相关文章推荐
- LeetCode: Best Time to Buy and Sell Stock I && II && III
- 122 Best Time to Buy and Sell Stock II [Leetcode]
- [LeetCode][Jave] Best Time to Buy and Sell Stock II
- LeetCode: Best Time to Buy and Sell Stock II
- [leetcode 122] Best Time to Buy and Sell Stock II
- [leetcode 122] Best Time to Buy and Sell Stock II
- c++ leetcode 算法题 Best Time to Buy and Sell Stock II
- leetcode笔记--Best Time to Buy and Sell Stock系列(I,II, III, IV)
- [LeetCode]122 Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II (简单题)
- [LeetCode]Best Time to Buy and Sell Stock II
- 【LeetCode】Best Time to Buy and Sell Stock II
- [C++]LeetCode: 77 Best Time to Buy and Sell Stock II (贪心算法)
- LeetCode: Best Time to Buy and Sell Stock II
- 【LeetCode】Best Time to Buy and Sell Stock II 解题报告
- LeetCode122 Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock II (LeetCode)
- Leetcode 122 Best Time to Buy and Sell Stock II
- LeetCode(122) Best Time to Buy and Sell Stock II
- leetcode Best Time to Buy and Sell Stock I II III