1768. 交替合并字符串

1768. 交替合并字符串_第1张图片

class Solution {
    public String mergeAlternately(String word1, String word2) {
        StringBuilder stringBuilder = new StringBuilder();
        int len1=word1.length();
        int len2=word2.length();
        int point1=0;
        int point2=0;
        while (point1<len1&&point2<len2){
            stringBuilder.append(word1.charAt(point1)).append(word2.charAt(point2));
            point1++;
            point2++;
        }
        while (point1<len1){
            stringBuilder.append(word1.charAt(point1));
            point1++;
        }
        while (point2<len2){
            stringBuilder.append(word2.charAt(point2));
            point2++;
        }
        return stringBuilder.toString();
    }
}

你可能感兴趣的:(算法,算法)