restructure solutions dir
This commit is contained in:
parent
f9ddad5f88
commit
ccb8b5673b
10 changed files with 0 additions and 0 deletions
23
solutions/1/q134/solution.go
Normal file
23
solutions/1/q134/solution.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package q134
|
||||
|
||||
func canCompleteCircuit(gas []int, cost []int) int {
|
||||
invalidated := 0
|
||||
start, current, tank := 0, 0, 0
|
||||
|
||||
for {
|
||||
tank = tank + gas[current] - cost[current]
|
||||
current = (current + 1) % len(gas)
|
||||
if tank < 0 {
|
||||
invalidated += (current - start + len(gas)) % len(gas)
|
||||
if invalidated >= len(gas) || current == start {
|
||||
return -1
|
||||
}
|
||||
start = current
|
||||
tank = 0
|
||||
} else if current == start {
|
||||
return start
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _ = canCompleteCircuit
|
||||
Loading…
Add table
Add a link
Reference in a new issue