leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0122.cpp (363B)
0 class Solution {
1 public:
2 int maxProfit(vector<int> &prices) {
3 int profit = 0;
4 prices.push_back(INT_MIN);
5 for (int i = 0, j = 0; i < prices.size() - 1; i++) {
6 while (prices[j] < prices[j + 1])
7 j++;
8 profit += prices[j] - prices[i];
9 i = j++;
10 }
11 return profit;
12 }
13 };