Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create gas_station.py #11821

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions data_structures/arrays/gas_station.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import List

Check failure on line 1 in data_structures/arrays/gas_station.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (UP035)

data_structures/arrays/gas_station.py:1:1: UP035 `typing.List` is deprecated, use `list` instead

class Solution:

Check failure on line 3 in data_structures/arrays/gas_station.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

data_structures/arrays/gas_station.py:1:1: I001 Import block is un-sorted or un-formatted
def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:

Check failure on line 4 in data_structures/arrays/gas_station.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N802)

data_structures/arrays/gas_station.py:4:9: N802 Function name `canCompleteCircuit` should be lowercase

Check failure on line 4 in data_structures/arrays/gas_station.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (UP006)

data_structures/arrays/gas_station.py:4:39: UP006 Use `list` instead of `List` for type annotation

Check failure on line 4 in data_structures/arrays/gas_station.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (UP006)

data_structures/arrays/gas_station.py:4:56: UP006 Use `list` instead of `List` for type annotation
total_gas = 0
current_gas = 0
start_station = 0

Check failure on line 8 in data_structures/arrays/gas_station.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

data_structures/arrays/gas_station.py:8:1: W293 Blank line contains whitespace
for i in range(len(gas)):
total_gas += gas[i] - cost[i]
current_gas += gas[i] - cost[i]

Check failure on line 12 in data_structures/arrays/gas_station.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

data_structures/arrays/gas_station.py:12:1: W293 Blank line contains whitespace
# If the current gas goes negative, we cannot start from the previous stations

Check failure on line 13 in data_structures/arrays/gas_station.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

data_structures/arrays/gas_station.py:13:89: E501 Line too long (90 > 88)
if current_gas < 0:
start_station = i + 1 # Start from the next station
current_gas = 0 # Reset current gas

# If total gas is negative, we can't complete the circuit
if total_gas < 0:
return -1
else:
return start_station

Check failure on line 23 in data_structures/arrays/gas_station.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

data_structures/arrays/gas_station.py:23:1: W293 Blank line contains whitespace
Loading