Skip to content

Commit 77a0507

Browse files
committed
Runtime: 1570 ms (Top 45.22%) | Memory: 36.4 MB (Top 42.14%)
1 parent b3988d8 commit 77a0507

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

scripts/algorithms/C/Car Fleet/Car Fleet.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
# Runtime: 1570 ms (Top 45.22%) | Memory: 36.4 MB (Top 42.14%)
12
class Solution:
23
def carFleet(self, target: int, position: List[int], speed: List[int]) -> int:
34
def computeArrivalTime(curr_pos, curr_speed):
45
nonlocal target
5-
return (target - curr_pos) / curr_speed
6+
return (target - curr_pos) / curr_speed
67
# avoid integer division, as a car may arrive at 5.2s and another at 5.6s
78

89
cars = list(zip(position, speed))
@@ -16,4 +17,4 @@ def computeArrivalTime(curr_pos, curr_speed):
1617
fleet += 1
1718
return fleet
1819
# time O(n logn): sort = (nlogn); loop = (n)
19-
# space O(n): depend on sort
20+
# space O(n): depend on sort

0 commit comments

Comments
 (0)