public int canCompleteCircuit(int[] gas, int[] cost) {
        if (gas == null || cost == null || gas.length != cost.length) return -1;

        int start = 0;
        int currLeft = 0, totalLeft = 0;
        for (int i = 0; i < gas.length; ++i) {
            currLeft += gas[i] - cost[i];
            if (currLeft < 0) {
                start = i + 1;
                currLeft = 0;
            }
            totalLeft += gas[i] - cost[i];
        }
        return totalLeft < 0 ? -1 : start;
    }