[LeetCode] 1768. Merge Strings Alternately

0

LeetCode

목록 보기
52/58
post-thumbnail

[LeetCode] 1768. Merge Strings Alternately

풀이

class Solution {
public:
    string mergeAlternately(string word1, string word2) {
        string answer = "";
        int index1 = 0;
        int index2 = 0;
        while(index1 < word1.length() && index2 < word2.length()){
            answer += word1[index1++];
            answer += word2[index2++];
        }
        while(index1 < word1.length()) answer += word1[index1++];
        while(index2 < word2.length()) answer += word2[index2++];

        return answer;
    }
};
profile
Be able to be vulnerable, in search of truth

0개의 댓글