Largest Merge Of Two Strings LeetCode solution in JavaScript

1
var largestMerge = function (word1, word2) {
2
let ans = "";
3
let w1 = 0,
4
w2 = 0;
5

6
while (w1 < word1.length && w2 < word2.length) {
7
if (word1[w1] > word2[w2]) ans += word1[w1++];
8
else if (word2[w2] > word1[w1]) ans += word2[w2++];
9
else {
10
const rest1 = word1.slice(w1);
11
const rest2 = word2.slice(w2);
12

13
if (rest1 > rest2) ans += word1[w1++];
14
else ans += word2[w2++];
15
}
16
}
17
ans += word1.slice(w1);
18
ans += word2.slice(w2);
19
return ans;
20
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0