Error:Runtime Error,Last executed input:[]


  • 0
    #include<vector>
    #include<algorithm>
    class Solution {
    public:
        int maxProfit(vector<int>& prices) {
            int i,j,k,l,v1,v2;
            vector<int> tempSort;
            for(i=0;i<(int)prices.size()-1;i++){
                for(j=i+1;j<(int)prices.size();j++){
                    v1 = prices[j]-prices[i];
                    tempSort.push_back(v1);
                    if(j < prices.size()-2){
                        for(k=j+1;k<(int)prices.size()-1;k++){
                            for(l=k+1;l<(int)prices.size();l++){
                                v2 = prices[l]-prices[k];
                                tempSort.push_back(v1+v2);
                            }
                        }
                    
              
                    }
            	}  
        }
        sort(tempSort.begin(),tempSort.end());
        return tempSort.back();
            
        }
    };
    

    where is this code error in?


  • 0
    H

    有没有考虑输入一个没有任何元素的数列时的情况?如:
    int[] test = {};


Log in to reply
 

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