File tree Expand file tree Collapse file tree 2 files changed +24
-22
lines changed Expand file tree Collapse file tree 2 files changed +24
-22
lines changed Original file line number Diff line number Diff line change 11class Solution :
22 def canCompleteCircuit (self , gas : List [int ], cost : List [int ]) -> int :
3- start , end = len (gas ) - 1 , 0
4- total = gas [start ] - cost [start ]
3+ if sum (gas ) < sum (cost ):
4+ return - 1
5+
6+ res = 0
7+ total = 0
8+ for i in range (len (gas )):
9+ total += gas [i ] - cost [i ]
10+
11+ if total < 0 :
12+ total = 0
13+ res = i + 1
514
6- while start >= end :
7- while total < 0 and start >= end :
8- start -= 1
9- total += gas [start ] - cost [start ]
10- if start == end :
11- return start
12- total += gas [end ] - cost [end ]
13- end += 1
14- return - 1
15+ return res
Original file line number Diff line number Diff line change 11class Solution :
22 def canCompleteCircuit (self , gas : List [int ], cost : List [int ]) -> int :
3- start , end = len (gas ) - 1 , 0
4- total = gas [start ] - cost [start ]
3+ if sum (gas ) < sum (cost ):
4+ return - 1
5+
6+ res = 0
7+ total = 0
8+ for i in range (len (gas )):
9+ total += gas [i ] - cost [i ]
10+
11+ if total < 0 :
12+ total = 0
13+ res = i + 1
514
6- while start >= end :
7- while total < 0 and start >= end :
8- start -= 1
9- total += gas [start ] - cost [start ]
10- if start == end :
11- return start
12- total += gas [end ] - cost [end ]
13- end += 1
14- return - 1
15+ return res
You can’t perform that action at this time.
0 commit comments