Add 交替合并字符串.py

This commit is contained in:
floraachy 2024-03-04 14:58:38 +08:00
parent f4f2a9771a
commit d88acf6584
1 changed files with 29 additions and 0 deletions

29
交替合并字符串.py Normal file
View File

@ -0,0 +1,29 @@
"""
题目给你两个字符串 word1 word2 请你从 word1 开始通过交替添加字母来合并字符串如果一个字符串比另一个字符串长就将多出来的字母追加到合并后字符串的末尾返回 合并后的字符串
示例 1
输入word1 = "abc", word2 = "pqr"
输出"apbqcr"
解释字符串合并情况如下所示
word1 a b c
word2 p q r
合并后 a p b q c r
示例 2
输入word1 = "ab", word2 = "pqrs"
输出"apbqrs"
解释注意word2 word1 "rs" 需要追加到合并后字符串的末尾
word1 a b
word2 p q r s
合并后 a p b q r s
示例 3
输入word1 = "abcd", word2 = "pq"
输出"apbqcd"
解释注意word1 word2 "cd" 需要追加到合并后字符串的末尾
word1 a b c d
word2 p q
合并后 a p b q c d
"""