leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1768.cpp (423B)
0 class Solution { 1 public: 2 string mergeAlternately(string word1, string word2) { 3 int i = 0, j = 0; 4 string res = ""; 5 6 while (i < word1.size() && j < word2.size()) { 7 res += word1[i++]; 8 res += word2[j++]; 9 } 10 11 while (i < word1.size()) 12 res += word1[i++]; 13 while (j < word2.size()) 14 res += word2[j++]; 15 16 return res; 17 } 18 };