1768. Merge Strings Alternately
給你兩個字串s1和s2,合併兩個字串並使其交錯。
Example:
Input: word1 = "abc", word2 = "pqr"
Output: "apbqcr"
Explanation: The merged string will be merged as so:
word1: a b c
word2: p q r
merged: a p b q c r
Example 2:
Input: word1 = "ab", word2 = "pqrs"
Output: "apbqrs"
Explanation: Notice that as word2 is longer, "rs" is appended to the end.
word1: a b
word2: p q r s
merged: a p b q r s
思路:
1.把兩個字串按照順序一個一個放到陣列,直到兩個都放完為止。
Java Code: