java.lang.Object
g1701_1800.s1768_merge_strings_alternately.Solution

public class Solution extends Object
1768 - Merge Strings Alternately.<p>Easy</p> <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p> <p>Return <em>the merged string.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> word1 = &ldquo;abc&rdquo;, word2 = &ldquo;pqr&rdquo;</p> <p><strong>Output:</strong> &ldquo;apbqcr&rdquo;</p> <p><strong>Explanation:</strong> The merged string will be merged as so:</p> <p>word1: a b c</p> <p>word2: p q r</p> <p>merged: a p b q c r</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> word1 = &ldquo;ab&rdquo;, word2 = &ldquo;pqrs&rdquo;</p> <p><strong>Output:</strong> &ldquo;apbqrs&rdquo;</p> <p><strong>Explanation:</strong> Notice that as word2 is longer, &ldquo;rs&rdquo; is appended to the end.</p> <p>word1: a b</p> <p>word2: p q r s</p> <p>merged: a p b q r s</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> word1 = &ldquo;abcd&rdquo;, word2 = &ldquo;pq&rdquo;</p> <p><strong>Output:</strong> &ldquo;apbqcd&rdquo;</p> <p><strong>Explanation:</strong> Notice that as word1 is longer, &ldquo;cd&rdquo; is appended to the end.</p> <p>word1: a b c d</p> <p>word2: p q</p> <p>merged: a p b q c d</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= word1.length, word2.length <= 100</code></li> <li><code>word1</code> and <code>word2</code> consist of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details