diff --git a/easy/merge_strings_alternately.py b/easy/merge_strings_alternately.py new file mode 100644 index 0000000..4781897 --- /dev/null +++ b/easy/merge_strings_alternately.py @@ -0,0 +1,20 @@ +# https://leetcode.com/problems/merge-strings-alternately + +class Solution: + def mergeAlternately(self, word1: str, word2: str) -> str: + i = 0 + j = 0 + result = [] + while i < len(word1) and j < len(word2): + result.append(word1[i]) + result.append(word2[j]) + i += 1 + j += 1 + while i < len(word1): + result.append(word1[i]) + i += 1 + while j < len(word2): + result.append(word2[j]) + j += 1 + return ''.join(result) +