Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.05 KB

_1768. Merge Strings Alternately.md

File metadata and controls

45 lines (32 loc) · 1.05 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 01, 2024

Last updated : July 01, 2024


Related Topics : Two Pointers, String

Acceptance Rate : 80.96 %


Solutions

Java

class Solution {
    public String mergeAlternately(String word1, String word2) {
        StringBuilder sb = new StringBuilder();

        int indx1 = 0;
        int indx2 = 0;
        for (; indx1 < word1.length() && indx2 < word2.length(); indx1++, indx2++) {
            sb.append(word1.charAt(indx1));
            sb.append(word2.charAt(indx2));
        }

        sb.append(word1.substring(indx1));
        sb.append(word2.substring(indx2));

        return sb.toString();
    }
}