Most concise C++ solution 12ms


  • 0
    D
    int maxProfit(vector<int>& prices) {
            int n = prices.size(), minm = INT_MAX, maxm = 0;
            for(int i = 0; i < n; i ++){
                minm = min(minm, prices[i]);
                maxm = max(prices[i] - minm, maxm);
            }
            return maxm;
        }

  • 0

    Don't lie. It's less concise than this.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.