I have passed 11/13 but I failed at test 12 ,could anyone help me out?


  • 0
    D
    public class Solution {
    public int canCompleteCircuit(int[] gas, int[] cost) {
        int num=0;
        int m=gas.length;
        int count=0;
        for(int i=0;i<m;i++){
            for(int j=i;;){
                if(j>m-1){
                    j=0;
                }
            num=num+gas[j];
            if(num-cost[j]<0){
                num=0;
                break;
                
            }else{
                num=num-cost[j];
                count++;
                j++;
                
            }
            if(count==m){
                return i;
            }
            
            
            }
        }
        
    return -1;
        
        
    }
    

    }


Log in to reply
 

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