Best Time to Buy and Sell Stock II
Description
Example
Link
Method
- x
- x
Example
- 1
class Solution { public: /** * @param prices: Given an integer array * @return: Maximum profit */ int maxProfit(vector<int> &prices) { // write your code here if (prices.empty()) { return 0; } int len = prices.size(); int profit = 0; for (int i = 1; i < len; ++i) { int diff = prices[i] - prices[i-1]; if (diff < 0) { continue; } profit += diff; } return profit; } };
Similar problems
x
Tags
x