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
commit e8b4c80f9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 2 deletions

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