Skip to content

Commit 3e2910f

Browse files
authored
Create largest-number-after-mutating-substring.py
1 parent d46a6d0 commit 3e2910f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def maximumNumber(self, num, change):
6+
"""
7+
:type num: str
8+
:type change: List[int]
9+
:rtype: str
10+
"""
11+
mutated = False
12+
result = map(int, list(num))
13+
for i, d in enumerate(result):
14+
if change[d] < d:
15+
if mutated:
16+
break
17+
elif change[d] > d:
18+
result[i] = str(change[d])
19+
mutated = True
20+
return "".join(map(str, result))

0 commit comments

Comments
 (0)