Skip to content

Commit be3ce1c

Browse files
committed
2019/12/22
1 parent bdf10c9 commit be3ce1c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Rust/389 Find the Difference.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use std::collections::HashMap;
2+
/*
3+
执行用时 :0 ms, 在所有 rust 提交中击败了100.00% 的用户
4+
内存消耗 :2 MB, 在所有 rust 提交中击败了100.00%的用户
5+
*/
6+
impl Solution {
7+
pub fn find_the_difference(s: String, t: String) -> char {
8+
let lowerAlphas: String = String::from("abcdefghijklmnopqrstuvwxyz");
9+
let mut dict: HashMap<char, i32> = HashMap::new();
10+
for c in s.chars() {
11+
match(dict.get(&c)) {
12+
Some(&val) => dict.insert(c, val+1),
13+
_ => dict.insert(c, 1),
14+
};
15+
}
16+
let mut dict2: HashMap<char, i32> = HashMap::new();
17+
for c in t.chars() {
18+
match(dict2.get(&c)) {
19+
Some(&val) => dict2.insert(c, val+1),
20+
_ => dict2.insert(c, 1),
21+
};
22+
}
23+
for c in lowerAlphas.chars() {
24+
match(dict2.get(&c)) {
25+
Some(&val2) => {
26+
match(dict.get(&c)) {
27+
Some(&val) => if(val != val2) {return c;}
28+
_ => return c,
29+
}
30+
},
31+
_ => (),
32+
};
33+
}
34+
return ' ';
35+
}
36+
}

0 commit comments

Comments
 (0)