Problem Solving/LeetCode
2023.04.18 Today's Challenge
fabichoi
2023. 4. 18. 23:45
https://leetcode.com/problems/merge-strings-alternately/
Merge Strings Alternately - LeetCode
Can you solve this real interview question? Merge Strings Alternately - You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional le
leetcode.com
오늘도 대충 풀면 되는 문제!
class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
res = []
l1, l2 = len(word1), len(word2)
for i in range(max(l1, l2)):
if l1 > i:
res.append(word1[i])
if l2 > i:
res.append(word2[i])
return ''.join(res)
반응형