Skip to content

Commit 5659414

Browse files
committed
Time: 175 ms (18.69%), Space: 26.3 MB (62.73%) - LeetHub
1 parent 675c909 commit 5659414

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# time complexity: O(n)
2+
# space complexity: O(1)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def minCost(self, colors: str, neededTime: List[int]) -> int:
8+
totalTime = 0
9+
currMaxTime = 0
10+
for i in range(len(neededTime)):
11+
if i > 0 and colors[i] != colors[i-1]:
12+
currMaxTime = 0
13+
14+
totalTime += min(currMaxTime, neededTime[i])
15+
currMaxTime = max(currMaxTime, neededTime[i])
16+
return totalTime
17+
18+
19+
colors = "abaac"
20+
neededTime = [1, 2, 3, 4, 5]
21+
print(Solution().minCost(colors, neededTime))

0 commit comments

Comments
 (0)