public int canCompleteCircuit(int[] gas, int[] cost) {
		if(gas == null || gas.length == 0 || cost == null || gas.length != cost.length) 
			return -1;
		
		int max = gas[gas.length-1] - cost[gas.length-1], maxIndex = gas.length-1, sum, i;
		sum = max;
		for(i = gas.length-2; i >= 0; i--) {
			sum += gas[i] - cost[i];
			if(sum > max) {
				max = sum;
				maxIndex = i;
			}
		}
		
		i = maxIndex;
		sum = 0;
		do{
			sum += gas[i] - cost[i];
			if(sum < 0) return -1;
			i++;
			if(i == gas.length) i = 0;
		} while(i != maxIndex);
		
		return maxIndex;
	}