leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1754.cpp (538B)


0 class Solution { 1 public: 2 string largestMerge(const string &word1, const string &word2) const { 3 const int n = size(word1), m = size(word2); 4 int i = 0, j = 0; 5 string res; 6 7 while (i < n && j < m) { 8 if (word1[i] == word2[j]) { 9 res += word1.substr(i) > word2.substr(j) ? word1[i++] : word2[j++]; 10 } else { 11 res += word1[i] > word2[j] ? word1[i++] : word2[j++]; 12 } 13 } 14 15 return res + word1.substr(i) + word2.substr(j); 16 } 17 };