public int canCompleteCircuit(final List<Integer> A, final List<Integer> B) {
// TODO: check A==null || B==null || A.size()!=B.size()
int tank=0, pos = 0;
for(int i=0; i < A.size(); ++i) {
tank += A.get(i) - B.get(i);
if (tank < 0) {
pos = i+1;
}
}
return (tank < 0) ? -1 : pos;
}
Shortest Java accepted code
super-dude
#1