1768. Merge Strings Alternately
https://leetcode.com/problems/merge-strings-alternately/
Python
class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
result = []
letters1 = list(word1[::-1])
letters2 = list(word2[::-1])
is_word1 = True
while letters1 or letters2:
if is_word1:
if letters1:
result.append(letters1.pop())
is_word1 = False
if not is_word1:
if letters2:
result.append(letters2.pop())
is_word1 = True
return ''.join(result)