solved using v = d/t
This commit is contained in:
parent
ba769e5cf8
commit
7d38ee51ce
@ -21,10 +21,28 @@ class Solution(object):
|
||||
:type speed: List[int]
|
||||
:rtype: int
|
||||
"""
|
||||
fleets = []
|
||||
for i,p in enumerate(position):
|
||||
print(f'{i}: {p}')
|
||||
n = len(speed)
|
||||
# Create velocity with position and speed
|
||||
v = [(position[i], speed[i]) for i in range(n)]
|
||||
v.sort()
|
||||
# Get Time based on displacement(distance from target) and speed
|
||||
time = [float(target - v[i][0]) / v[i][1] for i in range(n)]
|
||||
|
||||
curr = float('-inf')
|
||||
res = 0
|
||||
|
||||
# Find each fastest time of arrival per fleet based on new current time
|
||||
for i in range(n - 1, -1, -1):
|
||||
if time[i] > curr:
|
||||
print(f'curr is {curr}: time is {time[i]}')
|
||||
curr = time[i]
|
||||
res += 1
|
||||
|
||||
return res
|
||||
|
||||
|
||||
|
||||
obj = Solution()
|
||||
print(obj.carFleet(12,[10,8,0,5,3],[2,4,1,1,3])) # 3
|
||||
print(obj.carFleet(12,[10,8,0,5,3],[2,4,1,1,3])) # 3
|
||||
print(obj.carFleet(10,[3],[3])) # 1
|
||||
print(obj.carFleet(100,[0,2,4],[4,2,1])) # 1
|
||||
@ -1 +1,2 @@
|
||||
0]*len(temperatures)
|
||||
print(obj.carFleet(10,[3],[3])) # 1
|
||||
print(obj.carFleet(100,[0,2,4],[4,2,1])) # 1
|
||||
Loading…
Reference in New Issue
Block a user