Skip to main content

1768. Merge Strings Alternately - LeetCode

class Solution:
def mergeAlternately(self, w1: str, w2: str) -> str:
L1, L2 = len(w1), len(w2)
result = []
for i in range(max(L1, L2)):
if i < L1:
result.append(w1[i])
if i < L2:
result.append(w2[i])
return ''.join(result)