Skip to content

Commit 6fb3bb5

Browse files
authored
Create 1946-largest-number-after-mutating-substring.js
1 parent a65c908 commit 6fb3bb5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {string} num
3+
* @param {number[]} change
4+
* @return {string}
5+
*/
6+
const maximumNumber = function(num, change) {
7+
let res = ''
8+
const arr = num.split('')
9+
let prev = false, cnt = 0
10+
for(let i = 0, n = num.length; i < n; i++) {
11+
const cur = +num[i]
12+
if(change[cur] > cur) {
13+
cnt++
14+
prev = true
15+
arr[i] = change[cur]
16+
}
17+
if(change[cur] < cur) {
18+
if(cnt <= 0) continue
19+
else break
20+
}
21+
}
22+
23+
return arr.join('')
24+
};

0 commit comments

Comments
 (0)