Files

28 lines
542 B
C++

//
// Created by bob on 02/05/2026.
//
#include "merging_strings_alternatively.h"
class merging_strings_alternatively {
public:
string mergeAlternately(string word1, string word2) {
int i = 0;
string out = "";
int l1 = word1.length();
int l2 = word2.length();
while (i < l1 || i < l2)
{
if (i < l1){
out += word1[i];
}
if (i < l2){
out += word2[i];
}
i++;
}
return out;
}
};