You are viewing a single comment's thread. Return to all comments →
I iterate over the prices list in reverse:
long stockmax(vector<int> prices) { long res = 0; long cap = LONG_MIN; for(int i = prices.size() - 1; i >= 0; i--) { cap = max(cap, (long) prices[i]); res = res + cap - prices[i]; } return res; }
Seems like cookies are disabled on this browser, please enable them to open this website
Stock Maximize
You are viewing a single comment's thread. Return to all comments →
I iterate over the prices list in reverse: