feat(work): implement Gas Station solution and adjust formatting

This commit is contained in:
Prad Nukala committed 2026-09-29 17:03:33 -04:00
1 parent d2c645bef8
commit e11c9723f8
1 file changed
+16 -4
+16 -4
View File
@@ -54,15 +54,27 @@ you start.
Constraints: Constraints:
• n == gas.length == cost.length • n == gas.length == cost.length
• 1 <= n <= 10^5 • 1 <= n <= 10^5
• 0 <= gas[i], cost[i] <= 10^4 • 0 <= gas[i], cost[i] <= 10^4
• The input is generated such that the answer is unique. • The input is generated such that the answer is unique.
""" """
class Solution: class Solution:
def canCompleteCircuit(self, gas: list[int], cost: list[int]) -> int: def canCompleteCircuit(self, gas: list[int], cost: list[int]) -> int:
start, tank, total = 0, 0, 0
for i in range(len(gas)):
drive = gas[i] - cost[i]
tank = tank + drive
if tank < 0:
tank = 0
start = i + 1
total = total + drive
return start if total >= 0 else -1