mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Update 0134.加油站.md
添加 0134.加油站.md Golang 版本
This commit is contained in:
@ -240,6 +240,25 @@ class Solution:
|
|||||||
```
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
```go
|
||||||
|
func canCompleteCircuit(gas []int, cost []int) int {
|
||||||
|
curSum := 0
|
||||||
|
totalSum := 0
|
||||||
|
start := 0
|
||||||
|
for i := 0; i < len(gas); i++ {
|
||||||
|
curSum += gas[i] - cost[i]
|
||||||
|
totalSum += gas[i] - cost[i]
|
||||||
|
if curSum < 0 {
|
||||||
|
start = i+1
|
||||||
|
curSum = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if totalSum < 0 {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return start
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Javascript:
|
Javascript:
|
||||||
```Javascript
|
```Javascript
|
||||||
|
Reference in New Issue
Block a user