力扣 1768. 交替合并字符串

解法

1
2
3
4
5
6
7
8
9
def mergeAlternately(word1, word2):
ret = ""
i, a_len, b_len = 0, len(word1), len(word2)
while i < a_len and i < b_len:
ret += word1[i] + word2[i]
i += 1
if i < a_len: ret += word1[i:]
if i < b_len: ret += word2[i:]
return ret
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022 eightyninth
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信