문제링크
leetcode.com/problems/merge-strings-alternately/
Merge Strings Alternately - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
res = ''
arr1 = list(word1)
arr2 = list(word2)
maxLenght = max(len(word1), len(word2)) * 2
for i in range(maxLenght):
if i % 2 == 0 and arr1:
res += arr1.pop(0)
elif arr2:
res += arr2.pop(0)
return res
'알고리즘 > Leetcode' 카테고리의 다른 글
[leetcode/python3] 565. Array Nesting (0) | 2021.09.18 |
---|---|
[leetcode/python3] 1. Two Sum (0) | 2021.08.03 |
[leetcode/kotlin] 575.Distribute Candies (0) | 2021.03.16 |
[leetcode/kotlin] 104. Maximum Depth of Binary Tree (0) | 2020.12.05 |
[leetcode/kotlin] 1492. The kth Factor of n (0) | 2020.12.05 |