public int canCompleteCircuit(int[] gas, int[] cost) {
        int gasCostMin = 0;
        int gasMinIndex = -1;
        int totalGas = 0;
        int totalCost = 0;
        for(int i=0; i<gas.length; i++){
            if((gas[i]-cost[i]) < gasCostMin){
                gasCostMin = gas[i]-cost[i];
                gasMinIndex = i;
            }
            totalCost += cost[i];
            totalGas += gas[i];
        }
        if(totalGas >= totalCost){
            if(gasMinIndex == -1){
                return 0;
            }
            int j = gasMinIndex;
            while (true){
                if(gas[j]-cost[j]>0){
                    return j;
                }
                j++;
                if(j==gas.length){
                       j=0;
                }
            }
        }
        return -1;
    }