This commit is contained in:
parent
ed8c5a3088
commit
1d473fe723
1 changed files with 20 additions and 0 deletions
20
easy/merge_strings_alternately.py
Normal file
20
easy/merge_strings_alternately.py
Normal file
|
|
@ -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)
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue