Skip to content

Commit 89b888b

Browse files
committed
add 884
1 parent f32997b commit 89b888b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "S0884-uncommon-words-from-two-sentences"
3+
version = "0.1.0"
4+
authors = ["Xargin <cao1988228@163.com>"]
5+
edition = "2018"
6+
7+
[dependencies]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
fn main() {
2+
let res = Solution::uncommon_from_sentences("abc def".to_string(), "def aaa".to_string());
3+
println!("{:?}", res);
4+
}
5+
6+
struct Solution;
7+
8+
use std::collections::HashMap;
9+
impl Solution {
10+
pub fn uncommon_from_sentences(a: String, b: String) -> Vec<String> {
11+
let line = a + " " + b.as_str();
12+
let word_arr = line.split(" ").collect::<Vec<&str>>();
13+
14+
let mut counter = HashMap::new();
15+
word_arr.iter().for_each(|w| { counter.entry(w).and_modify(|e| *e += 1).or_insert(1); });
16+
counter.iter().filter(|(_, &c)| c == 1).map(|(w, _)| w.to_string()) .collect::<Vec<String>>()
17+
}
18+
}

0 commit comments

Comments
 (0)