/
githubmirror
/
LeetCode-Go
Обзор
Документация
Войти
/
githubmirror
/
LeetCode-Go
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
leetcode/0134.Gas-Station/Gas.go
26 строк
356 B
hechenghao
add no.134 answer
21 окт 2024, 08:14
21 окт 2024, 08:14
281ae8b
Код
Авторство
О чём код?
package leetcode func canCompleteCircuit(gas []int, cost []int) int { totalGas := 0 totalCost := 0 currGas := 0 start := 0 for i := 0; i < len(gas); i++ { totalGas += gas[i] totalCost += cost[i] currGas += gas[i] - cost[i] if currGas < 0 { start = i + 1 currGas = 0 } } if totalGas < totalCost { return -1 } return start }