Why my solution can't AC ?


  • 0
    X
    int maxProfit(vector<int>& prices) {
    int low = 0x7fffffff;
    int max = 0x80000000;
    int mark_i;
    for(int i = 0; i < prices.size(); i++){
        if(prices[i] < low){
            low = prices[i];
            mark_i = i;
        }
    }
    if(mark_i == prices.size()-1||prices.size()==0)
        return 0;
    else{
        for(int j = mark_i+1; j < prices.size(); j++){
            if(prices[j] > max){
                max = prices[j];
            }
        return max-low;
    }
    

    }


Log in to reply
 

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