1946. Largest Number After Mutating Substring
https://leetcode.com/problems/largest-number-after-mutating-substring
Description
You are given a string num
, which represents a large integer. You are also given a 0-indexed integer array change
of length 10
that maps each digit 0-9
to another digit. More formally, digit d
maps to digit change[d]
.
You may choose to mutate a single substring of num
. To mutate a substring, replace each digit num[i]
with the digit it maps to in change
(i.e. replace num[i]
with change[num[i]]
).
Return a string representing the largest possible integer after mutating (or choosing not to) a single substring of num
.
A substring is a contiguous sequence of characters within the string.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= num.length <= 105
num
consists of only digits0-9
.change.length == 10
0 <= change[d] <= 9
ac
Last updated