public int canCompleteCircuit(int[] gas, int[] cost) {
        int[] dif = new int[gas.length +1];
        for(int i =0;i< gas.length;i++){
            dif[i] = gas[i] - cost[i];
            dif[dif.length-1] += dif[i];
        }
        if(dif[dif.length-1] < 0)
            return -1;

        int length  = gas.length;
        int  tank  = 0;
        for(int i =0;i< gas.length;i++){
            if(dif[i] >= 0 ){
                tank = 0;
                for(int j =0;j< length ;j++){
                    tank+= dif[(j+i)% length];
                    if(tank < 0){
                        i=(i+j)%length;
                        break;
                    }
                }
                if(tank >=0)return i;
            }
        }
        return -1;
    }