MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / merge_alternately

Function merge_alternately

1768-merge-strings-alternately.rs:22–40  ·  view source on GitHub ↗
(word1: String, word2: String)

Source from the content-addressed store, hash-verified

20// 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
21
22pub fn merge_alternately(word1: String, word2: String) -> String {
23 let mut res: Vec<char> = vec!();
24 let max_len;
25 if word1.len() > word2.len() {
26 max_len = word1.len();
27 } else {
28 max_len = word2.len();
29 }
30
31 for i in 0..max_len {
32 if i < word1.len() {
33 res.push(word1.chars().nth(i).unwrap());
34 }
35 if i < word2.len() {
36 res.push(word2.chars().nth(i).unwrap());
37 }
38 }
39 res.into_iter().collect()
40}
41
42fn main() {
43 println!("{:?}", merge_alternately("abcd".to_string(), "m".to_string()));

Callers

nothing calls this directly

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected