← switch

1768. Merge Strings Alternately

easy

Two Pointers · String

read the problem on leetcode →

first solved 17 Dec 2023

python
class Solution(object):
    def mergeAlternately(self, word1, word2):
        """
        :type word1: str
        :type word2: str
        :rtype: str
        """

        results=""
        for i in range(min(len(word1),len(word2))):
            results+=word1[i]
            results+=word2[i]
            
            
        if min(len(word1),len(word2))==len(word1):
            results+=word2[len(word1):]
            return results
        results+=word1[len(word2):]
        return results