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)