We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 912415f commit 86771fbCopy full SHA for 86771fb
1894-merge-strings-alternately/solution.py
@@ -5,12 +5,13 @@
5
6
class Solution:
7
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):
+ result = []
+ n = max(len(word1), len(word2))
+
11
+ for i in range(n):
12
if i < len(word1):
13
result += word1[i]
14
if i < len(word2):
15
result += word2[i]
16
- return result
17
+ return ''.join(result)
0 commit comments