日期 题目地址:https://leetcode-cn.com/problems/merge-strings-alternately/ 题目描述 给你两个字符串word1和word2。请你从word1开始,通过交替添加字母来合并字符串。如果一个字符串比另一个字符串长,就将多出来的字母追加到合并后字符串的末尾。 返回 合并后的字符串 。 示例1: 输入:word1 ="abc", word...
Runtime: 24 ms, faster than 100.00% of Python online submissions for Merge Strings Alternately. Memory Usage: 13.6 MB, less than 100.00% of Python online submissions for Merge Strings Alternately. 1 2 原题链接:https://leetcode.com/problems/merge-strings-alternately/ 您的支持是我最大的动力版...
核心代码如下: stringmergeAlternately(stringword1,stringword2){ // cout << word1.size() << endl; intlen1 = word1.size(); intlen2 = word2.size(); inti =0, j =0; stringres; res.reserve(len1 + len2); while(i < len1 || j < len2) { if(i < len1) { res.push_back(wo...