bumpsoo 2024-11-04 23:51:22 +09:00
parent ed8c5a3088
commit 1d473fe723

View file

@ -0,0 +1,20 @@
# https://leetcode.com/problems/merge-strings-alternately
class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
i = 0
j = 0
result = []
while i < len(word1) and j < len(word2):
result.append(word1[i])
result.append(word2[j])
i += 1
j += 1
while i < len(word1):
result.append(word1[i])
i += 1
while j < len(word2):
result.append(word2[j])
j += 1
return ''.join(result)