Search
 
SCRIPT & CODE EXAMPLE
 

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;
       
    }
};
Comment

PREVIOUS NEXT
Code Example
Cpp :: glm has no member value_ptr 
Cpp :: Lambda capture as const cpp 
Cpp :: UENUM ue4 
Cpp :: how to check if vector is ordered c++ 
Cpp :: c++ get data type 
Cpp :: printing in column c++ 
Cpp :: full implementation of binary search tree in C++ 
Cpp :: string in c++ 
Cpp :: put function in cpp 
Cpp :: sliding window c++ 
Cpp :: volumeof a sphere 
Cpp :: auto in c++ 
Cpp :: Character cin(userInput) in c++ 
Cpp :: how to find product of a given numbers in c++ 
Cpp :: shortest path in unweighted graph bfs 
Cpp :: ifstream 
Cpp :: runtime 
Cpp :: sum of n natural numbers 
Cpp :: c++ else if 
Cpp :: public method 
Cpp :: sort an array in c++ 
Cpp :: replace a char in string c++ at a specific index 
Cpp :: double plus overload 
Cpp :: C++ ss 
Cpp :: heapsort 
Cpp :: COs trigonometric function 
Cpp :: 3. The method indexOf, part of the List interface, returns the index of the first occurrence of an object in a List. What does the following code fragment do? 
Cpp :: initalising array c++ 
Cpp :: function and function prototype. 
Cpp :: why wont a function stop C++ 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =