Problem
You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.
Return the merged string...
Algorithm
Insert numbers alternately
Code
python3
class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
ans = ""
L1, L2, P1, P2 = len(word1), len(word2), 0, 0
while P1 < L1 or P2 < L2:
if P1 < L1:
ans += word1[P1]
P1 += 1
if P2 < L2:
ans += word2[P2]
P2 += 1
return ans