Merge pull request #137 from LiangDazhu/patch-7

添加 0134.加油站 python版本
This commit is contained in:
Carl Sun
2021-05-16 09:45:52 +08:00
committed by GitHub

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