My simple submission C++ 14ms

  • 0

    class Solution {
    int maxProfit(vector<int> &prices) {
    int n=prices.size();

        int profit = 0;
        int bot=INT_MAX;
        for (int i=0; i<n; ++i){
            if (prices[i]<bot)
                bot = prices[i];
            else if ((prices[i]-bot)>profit)
                profit = (prices[i]-bot);
        return profit;


Log in to reply

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