Skip to content

Commit a049d36

Browse files
committed
Time: 54 ms (11.37%), Space: 53.8 MB (73.15%) - LeetHub
source:46eebe091ad60c7905f1ac2c77e75708afce65e1
1 parent 27c43f4 commit a049d36

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {string} word1
3+
* @param {string} word2
4+
* @return {string}
5+
*/
6+
var mergeAlternately = function(word1, word2) {
7+
let result = [];
8+
const maxLength = Math.max(word1.length, word2.length);
9+
10+
for (let i = 0; i < maxLength; i++) {
11+
if (word1[i]) {
12+
result.push(word1[i]);
13+
}
14+
15+
if (word2[i]) {
16+
result.push(word2[i]);
17+
}
18+
}
19+
20+
21+
return result.join('');
22+
};

0 commit comments

Comments
 (0)