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)


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