LeetCode Entry
1768. Merge Strings Alternately
we can use sequence zip operator
1768. Merge Strings Alternately easy
fun mergeAlternately(word1: String, word2: String): String =
(word1.asSequence().zip(word2.asSequence()) { a, b -> "$a$b" } +
word1.drop(word2.length) + word2.drop(word1.length))
.joinToString("")
Join me on Telegram
https://t.me/leetcode_daily_unstoppable/184
Intuition
Do what is asked. Handle the tail.
Approach
- we can use sequence
zipoperator - for the tail, consider
dropComplexity
- Time complexity: \(O(n)\)
- Space complexity: \(O(n)\)