Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
       
    }
};
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Merge #Strings #Alternately #leetcode #solution
ADD COMMENT
Topic
Name
7+3 =