A simple C solution [Accepted]


  • 0
    B
    int maxProfit(int* prices, int pricesSize) {
        int temp_min=prices[0];
        int result=0;
        for(int i=1;i<pricesSize;i++)
        { 
            if(temp_min>prices[i])
            {
                temp_min=prices[i];
            }else if(result<prices[i]-temp_min)
            {
                result=prices[i]-temp_min;
            }
        }
        return result;
    }
    

Log in to reply
 

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