(int[] gas, int[] cost)
| 1 | class Solution { |
| 2 | public int canCompleteCircuit(int[] gas, int[] cost) { |
| 3 | |
| 4 | int index=0,tank=0,total=0; |
| 5 | for(int i=0;i<gas.length;i++) |
| 6 | { |
| 7 | int consume=gas[i]-cost[i]; |
| 8 | tank+=consume; |
| 9 | if(tank<0) |
| 10 | { |
| 11 | index=i+1; |
| 12 | tank=0; |
| 13 | } |
| 14 | total+=consume; |
| 15 | } |
| 16 | return (total<0)?-1:(index); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 |
nothing calls this directly
no outgoing calls
no test coverage detected