mirror of
https://github.com/mudabbir-ahmad/Leet-Code-prog.git
synced 2026-10-08 02:30:21 +00:00
28 lines
542 B
C++
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;
|
|
}
|
|
}; |