class Solution {
public:
string largestMerge(string word1, string word2) {
string ans;
int i = 0, j = 0;
while (i < word1.size() || j < word2.size()) {
if (i < word1.size() && word1.substr(i) > word2.substr(j)) {
ans += word1[i++];
} else { // i > word1.size() || word1.substr(i) > word2.substr(j)
ans += word2[j++];
}
}
return ans;
}
};
贪心 + 双指针
标签:string,20221224,每日,ans,substr,word1,word2,size From: https://www.cnblogs.com/zhanghanLeo/p/17002460.html