File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
S0884-uncommon-words-from-two-sentences Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change
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 ]
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments