Class Solution
java.lang.Object
g1901_2000.s1946_largest_number_after_mutating_substring.Solution
1946 - Largest Number After Mutating Substring.<p>Medium</p>
<p>You are given a string <code>num</code>, which represents a large integer. You are also given a <strong>0-indexed</strong> integer array <code>change</code> of length <code>10</code> that maps each digit <code>0-9</code> to another digit. More formally, digit <code>d</code> maps to digit <code>change[d]</code>.</p>
<p>You may <strong>choose</strong> to <strong>mutate a single substring</strong> of <code>num</code>. To mutate a substring, replace each digit <code>num[i]</code> with the digit it maps to in <code>change</code> (i.e. replace <code>num[i]</code> with <code>change[num[i]]</code>).</p>
<p>Return <em>a string representing the <strong>largest</strong> possible integer after <strong>mutating</strong> (or choosing not to) a <strong>single substring</strong> of</em> <code>num</code>.</p>
<p>A <strong>substring</strong> is a contiguous sequence of characters within the string.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> num = “132”, change = [9,8,5,0,3,6,4,2,6,8]</p>
<p><strong>Output:</strong> “832”</p>
<p><strong>Explanation:</strong> Replace the substring “1”:</p>
<ul>
<li>1 maps to change[1] = 8. Thus, “132” becomes “832”.</li>
</ul>
<p>“832” is the largest number that can be created, so return it.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> num = “021”, change = [9,4,3,5,7,2,1,9,0,6]</p>
<p><strong>Output:</strong> “934”</p>
<p><strong>Explanation:</strong> Replace the substring “021”:</p>
<ul>
<li>
<p>0 maps to change[0] = 9.</p>
</li>
<li>
<p>2 maps to change[2] = 3.</p>
</li>
<li>
<p>1 maps to change[1] = 4.</p>
</li>
</ul>
<p>Thus, “021” becomes “934”.</p>
<p>“934” is the largest number that can be created, so return it.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> num = “5”, change = [1,4,7,5,3,2,5,6,9,4]</p>
<p><strong>Output:</strong> “5”</p>
<p><strong>Explanation:</strong> “5” is already the largest number that can be created, so return it.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= num.length <= 10<sup>5</sup></code></li>
<li><code>num</code> consists of only digits <code>0-9</code>.</li>
<li><code>change.length == 10</code></li>
<li><code>0 <= change[d] <= 9</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maximumNumber
-