Skip to content

Commit 86771fb

Browse files
committed
Sync LeetCode submission Runtime - 37 ms (55.34%), Memory - 17.5 MB (53.43%)
1 parent 912415f commit 86771fb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

1894-merge-strings-alternately/solution.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
class Solution:
77
def mergeAlternately(self, word1: str, word2: str) -> str:
8-
result = ''
9-
max_length = max(len(word1), len(word2))
10-
for i in range(max_length):
8+
result = []
9+
n = max(len(word1), len(word2))
10+
11+
for i in range(n):
1112
if i < len(word1):
1213
result += word1[i]
1314
if i < len(word2):
1415
result += word2[i]
1516

16-
return result
17+
return ''.join(result)

0 commit comments

Comments
 (0)