Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 509 Bytes

1768.-merge-strings-alternately.md

File metadata and controls

24 lines (17 loc) · 509 Bytes

1768. Merge Strings Alternately

class Solution:
    def mergeAlternately(self, word1: str, word2: str) -> str:
        
        ans = ""
        i = j = 0
        idx = 0
        while i < len(word1) and j < len(word2):
            if idx % 2 == 0 :
                ans += word1[i]
                i += 1
                
            else:
                ans += word2[j]
                j += 1
            idx += 1 
            
        
        
        return ans + word1[i:] + word2[j:]