Skip to content

Commit 4fd8696

Browse files
authored
Create minimum-deletion-cost-to-avoid-repeating-letters.py
1 parent b8804e2 commit 4fd8696

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def minCost(self, s, cost):
6+
"""
7+
:type s: str
8+
:type cost: List[int]
9+
:rtype: int
10+
"""
11+
result = accu = max_cost = 0
12+
for i in xrange(len(s)):
13+
if i and s[i] != s[i-1]:
14+
result += accu-max_cost
15+
accu = max_cost = 0
16+
accu += cost[i]
17+
max_cost = max(max_cost, cost[i])
18+
result += accu-max_cost
19+
return result

0 commit comments

Comments
 (0)