Skip to content

Commit 145b1aa

Browse files
committed
feat: add rust solution to lc problem: No.0884
No.0884.Uncommon Words from Two Sentences
1 parent 5ae0b7d commit 145b1aa

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

solution/0800-0899/0884.Uncommon Words from Two Sentences/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,31 @@ func uncommonFromSentences(s1 string, s2 string) []string {
152152
}
153153
```
154154

155+
### **Rust**
156+
157+
```rust
158+
use std::collections::HashMap;
159+
160+
impl Solution {
161+
pub fn uncommon_from_sentences(s1: String, s2: String) -> Vec<String> {
162+
let mut map = HashMap::new();
163+
for s in s1.split(' ') {
164+
map.insert(s, !map.contains_key(s));
165+
}
166+
for s in s2.split(' ') {
167+
map.insert(s, !map.contains_key(s));
168+
}
169+
let mut res = Vec::new();
170+
for (k, v) in map {
171+
if v {
172+
res.push(String::from(k))
173+
}
174+
}
175+
res
176+
}
177+
}
178+
```
179+
155180
### **...**
156181

157182
```

solution/0800-0899/0884.Uncommon Words from Two Sentences/README_EN.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,31 @@ func uncommonFromSentences(s1 string, s2 string) []string {
161161
}
162162
```
163163

164+
### **Rust**
165+
166+
```rust
167+
use std::collections::HashMap;
168+
169+
impl Solution {
170+
pub fn uncommon_from_sentences(s1: String, s2: String) -> Vec<String> {
171+
let mut map = HashMap::new();
172+
for s in s1.split(' ') {
173+
map.insert(s, !map.contains_key(s));
174+
}
175+
for s in s2.split(' ') {
176+
map.insert(s, !map.contains_key(s));
177+
}
178+
let mut res = Vec::new();
179+
for (k, v) in map {
180+
if v {
181+
res.push(String::from(k))
182+
}
183+
}
184+
res
185+
}
186+
}
187+
```
188+
164189
### **...**
165190

166191
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::collections::HashMap;
2+
3+
impl Solution {
4+
pub fn uncommon_from_sentences(s1: String, s2: String) -> Vec<String> {
5+
let mut map = HashMap::new();
6+
for s in s1.split(' ') {
7+
map.insert(s, !map.contains_key(s));
8+
}
9+
for s in s2.split(' ') {
10+
map.insert(s, !map.contains_key(s));
11+
}
12+
let mut res = Vec::new();
13+
for (k, v) in map {
14+
if v {
15+
res.push(String::from(k))
16+
}
17+
}
18+
res
19+
}
20+
}

0 commit comments

Comments
 (0)