1768. Merge Strings Alternately Easy
1/**
2 * [1768] Merge Strings Alternately
3 *
4 * You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.
5 *
6 * Return the merged string.
7 *
8 *
9 * Example 1:
10 *
11 *
12 * Input: word1 = "abc", word2 = "pqr"
13 * Output: "apbqcr"
14 * Explanation: The merged string will be merged as so:
15 * word1: a b c
16 * word2: p q r
17 * merged: a p b q c r
18 *
19 *
20 * Example 2:
21 *
22 *
23 * Input: word1 = "ab", word2 = "pqrs"
24 * Output: "apbqrs"
25 * Explanation: Notice that as word2 is longer, "rs" is appended to the end.
26 * word1: a b
27 * word2: p q r s
28 * merged: a p b q r s
29 *
30 *
31 * Example 3:
32 *
33 *
34 * Input: word1 = "abcd", word2 = "pq"
35 * Output: "apbqcd"
36 * Explanation: Notice that as word1 is longer, "cd" is appended to the end.
37 * word1: a b c d
38 * word2: p q
39 * merged: a p b q c d
40 *
41 *
42 *
43 * Constraints:
44 *
45 *
46 * 1 <= word1.length, word2.length <= 100
47 * word1 and word2 consist of lowercase English letters.
48 *
49 */
50pub struct Solution {}
51
52// problem: https://leetcode.com/problems/merge-strings-alternately/
53// discuss: https://leetcode.com/problems/merge-strings-alternately/discuss/?currentPage=1&orderBy=most_votes&query=
54
55// submission codes start here
56
57impl Solution {
58 pub fn merge_alternately(word1: String, word2: String) -> String {
59 String::new()
60 }
61}
62
63// submission codes end
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
70 fn test_1768() {
71 }
72}
73
Back
© 2025 bowen.ge All Rights Reserved.