[LeetCode] 1768. Merge Strings Alternately

김민우·2023년 4월 18일
0

알고리즘

목록 보기
177/189

- Problem

1768. Merge Strings Alternately

- 내 풀이

class Solution:
    def mergeAlternately(self, word1: str, word2: str) -> str:
        merged_string = ""

        for c1, c2 in zip(word1, word2):
            merged_string += c1 + c2
        
        if len(word1) > len(word2):
            return merged_string + word1[len(word2):]
        elif len(word1) < len(word2):
            return merged_string + word2[len(word1):]
        return merged_string

- 결과

profile
Pay it forward.

0개의 댓글