You are given two strings, word1 and word2. You want to construct a string merge of length equal to the combined length of both strings.
While either word1 or word2 is not empty, you can perform one of the following actions:
If word1 is not empty, remove the first character from word1 and append it to merge.
If word2 is not empty, remove the first character from word2 and append it to merge.
Return the lexicographically largest merge that can be constructed.
Note: A string
ais lexicographically larger than a stringbof the same length if, at the first position where they differ, the character inais greater than the corresponding character inb.
Constraints:
word1.length, word2.length
word1 and word2 consist only of lowercase English letters.
You are given two strings, word1 and word2. You want to construct a string merge of length equal to the combined length of both strings.
While either word1 or word2 is not empty, you can perform one of the following actions:
If word1 is not empty, remove the first character from word1 and append it to merge.
If word2 is not empty, remove the first character from word2 and append it to merge.
Return the lexicographically largest merge that can be constructed.
Note: A string
ais lexicographically larger than a stringbof the same length if, at the first position where they differ, the character inais greater than the corresponding character inb.
Constraints:
word1.length, word2.length
word1 and word2 consist only of lowercase English letters.