Answers for "1768. Merge Strings Alternately leetcode solution in c++"

C++
0

1768. Merge Strings Alternately leetcode solution in c++

class Solution {
public:
    string mergeAlternately(string word1, string word2) {
        string s;
        
        int n1=word1.length();
        int n2=word2.length();
        
        for(int i=0; i<n1||i<n2; i++)
        {
            if(i<n1)  s+=word1[i];
            if(i<n2)  s+=word2[i];
        }
        
        return s;
       
    }
};
Posted by: Guest on March-10-2022

Browse Popular Code Answers by Language