|
| 1 | +class Solution: |
| 2 | + def mergeAlternately(self, word1: str, word2: str) -> str: |
| 3 | + result = [] |
| 4 | + |
| 5 | + for index in range(max(len(word1), len(word2))): |
| 6 | + if index < len(word1): |
| 7 | + result.append(word1[index]) |
| 8 | + if index < len(word2): |
| 9 | + result.append(word2[index]) |
| 10 | + |
| 11 | + return ''.join(result) |
| 12 | + |
| 13 | +assert Solution().mergeAlternately(word1="abc", word2="pqr") == "apbqcr", "Test 1 Failed" |
| 14 | +assert Solution().mergeAlternately(word1="ab", word2="pqrs") == "apbqrs", "Test 2 Failed" |
| 15 | +assert Solution().mergeAlternately(word1="abcd", word2="pq") == "apbqcd", "Test 3 Failed" |
0 commit comments