Merge Strings Alternately - LeetCode 1768 - Python Solution

preview_player
Показать описание
Solution Blog (sign into leetcode to view):

Just zip them together and combine each iteration.

Take the difference and slice the longer word by that difference.

Where M is length of word1, and N is length of word2

Time complexity: O(M + N)
Space complexity: O(M + N)

You can also use zip_longest to handle the longer word and make the fillvalue '''

Hope this helped - have an awesome day!
#python #leetcode #tutorial
Рекомендации по теме
Комментарии
Автор

Great video, why didnt we have to negate word2 with the diff?

bananaboydan