题目地址:https://leetcode-cn.com/problems/merge-strings-alternately/ 题目描述 给你两个字符串word1和word2。请你从word1开始,通过交替添加字母来合并字符串。如果一个字符串比另一个字符串长,就将多出来的字母追加到合并后字符串的末尾。 返回 合并后的字符串 。 示例1: 输入:word1 ="abc", word2 ="...
核心代码如下: 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...
word1: a b c d word2: p q 合并后: a p b q c d 提示: 1 <= word1.length, word2.length <= 100 word1和word2由小写英文字母组成 排序:最热 1 2 3 4 5 6 classSolution{ public: stringmergeAlternately(stringword1,stringword2) { } };...
word1: a b c d word2: p q 合并后: a p b q c d 提示: 1 <= word1.length, word2.length <= 100 word1和word2由小写英文字母组成 排序:最热 1 2 3 4 5 6 classSolution{ public: stringmergeAlternately(stringword1,stringword2) { } };...
祖传的手艺不想丢了,所以按顺序写一个leetcode的题解。计划每日两题,争取不卡题吧。 1768.交替合并字符串 力扣leetcode-cn.com/problems/merge-strings-alternately/ 比较基础的题目,使用两个指针分别从两个字符串的头部开始向后扫,按照先1后2的顺序进行合并。当某一个指针当前字符串末尾时则停止,然后将合并...
word1和word2由小写英文字母组成 Runtime:1 ms, faster than85.58%of Java online submissions for Merge Strings Alternately. Memory Usage:41.5 MB, less than68.46%of Java online submissions for Merge Strings Alternately. --- 直接模拟即可。
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/merge-strings-alternately 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 2. 解题 双指针模拟 代码语言:javascript 代码运行次数:0 运行 AI代码解释 class Solution { public: string mergeAlternately(string word1, string wo...
word1: a b c d word2: p q 合并后: a p b q c d ``` 提示: + `1 <= word1.length, word2.length <= 100` + `word1` 和 `word2` 由小写英文字母组成 ### 地址 https://leetcode-cn.com/problems/merge-strings-alternately ### 题意 > 简单问题,直接暴力或者前缀和什么的 ### ...
Merge Strings Alternately Greatest Common Divisor of Strings Kids with the Greatest Number of Candies Can Place Flowers Reverse Vowels of a String Reverse Words in a String Product of Array Except Self Increasing Triplet Sequence String Compression ...
1768 Merge Strings Alternately Easy Go 1769 Minimum Number of Operations to Move All Balls to Each Box Medium Python 1784 Check if Binary String Has at Most One Segment of Ones Easy Go 1785 Minimum Elements to Add to Form a Given Sum Medium Go 1786 Number of Restricted Paths From First to...