[LeetCode] Best Time to Buy and Sell Stock II
2013-01-28 19:42
411 查看
class Solution { public: int maxProfit(vector<int> &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function int ret = 0; for (int i = 1; i < prices.size(); i++) if (prices[i] > prices[i - 1]) ret += prices[i] - prices[i - 1]; return ret; } };
Small Case: 12ms
Large Case: 44ms
Time: O(n)
Space: O(1)
相关文章推荐
- 《leetCode》:Best Time to Buy and Sell Stock II
- leetcode Best Time to Buy and Sell Stock I&&II&&III
- 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 I II III
- 【LeetCode】Best Time to Buy and Sell Stock I && II && III
- LeetCode | Best Time to Buy and Sell Stock II
- 第一周:( LeetCode ) Best Time to Buy and Sell Stock I II III(c++)
- 【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
- [Leetcode] Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock I,II,III
- LEETCODE: Best Time to Buy and Sell Stock II
- LeetCode 121-123 Best Time to Buy and Sell Stock I II III
- [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
- LeetCode之Best Time to Buy and Sell Stock II