Skip to content

Commit 0df78df

Browse files
committed
Runtime: 7 ms (Top 98.2%) | Memory: 13.31 MB (Top 45.5%)
1 parent b05d40d commit 0df78df

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
class Solution:
2-
def mergeAlternately(self, word1: str, word2: str) -> str:
3-
4-
res=''
5-
6-
for i in range(min(len(word1),len(word2))):
7-
res += word1[i] + word2[i]
8-
9-
return res + word1[i+1:] + word2[i+1:]
1+
# Runtime: 7 ms (Top 98.2%) | Memory: 13.31 MB (Top 45.5%)
2+
3+
class Solution(object):
4+
def mergeAlternately(self, word1, word2):
5+
i=0
6+
j=0
7+
st=[]
8+
while i<len(word1) and j<len(word2):
9+
st.append(word1[i])
10+
st.append(word2[j])
11+
i+=1
12+
j+=1
13+
while j<len(word2):
14+
st.append(word2[j])
15+
j+=1
16+
while i<len(word1):
17+
st.append(word1[i])
18+
i+=1
19+
return "".join(st)

0 commit comments

Comments
 (0)