Update 0134.加油站.md

Added python version code
This commit is contained in:
LiangDazhu
2021-05-15 23:11:10 +08:00
committed by GitHub
parent 8c3d8aab25
commit 3c0ceba064

View File

@ -223,7 +223,21 @@ class Solution {
``` ```
Python Python
```python
class Solution:
def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
start = 0
curSum = 0
totalSum = 0
for i in range(len(gas)):
curSum += gas[i] - cost[i]
totalSum += gas[i] - cost[i]
if curSum < 0:
curSum = 0
start = i + 1
if totalSum < 0: return -1
return start
```
Go Go