File tree 1 file changed +10
-9
lines changed
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -17,14 +17,16 @@ use std::collections::HashSet;
17
17
// }
18
18
// }
19
19
20
+ // https://github.com/kamyu104/LeetCode-Solutions/blob/master/Python/find-the-difference.py#L18
20
21
pub struct Solution3 { }
21
22
impl Solution3 {
22
23
pub fn find_the_difference ( s : String , t : String ) -> char {
23
24
let s_chars: HashSet < char > = s. chars ( ) . collect ( ) ;
24
- let t_chars: HashSet < char > = t. chars ( ) . collect ( ) ;
25
- // or https://doc.rust-lang.org/std/collections/struct.HashSet.html#method.symmetric_difference
26
- let diff: HashSet < & char > = t_chars. difference ( & s_chars) . collect ( ) ;
27
- * ( diff. into_iter ( ) . collect :: < Vec < & char > > ( ) [ 0 ] )
25
+ let mut t_chars: HashSet < char > = t. chars ( ) . collect ( ) ;
26
+ s_chars. iter ( ) . for_each ( |c| {
27
+ t_chars. remove ( c) ;
28
+ } ) ;
29
+ t_chars. into_iter ( ) . collect :: < Vec < char > > ( ) [ 0 ]
28
30
}
29
31
}
30
32
@@ -40,11 +42,10 @@ pub struct Solution5 {}
40
42
impl Solution5 {
41
43
pub fn find_the_difference ( s : String , t : String ) -> char {
42
44
let s_chars: HashSet < char > = s. chars ( ) . collect ( ) ;
43
- let mut t_chars: HashSet < char > = t. chars ( ) . collect ( ) ;
44
- s_chars. iter ( ) . for_each ( |c| {
45
- t_chars. remove ( c) ;
46
- } ) ;
47
- t_chars. into_iter ( ) . collect :: < Vec < char > > ( ) [ 0 ]
45
+ let t_chars: HashSet < char > = t. chars ( ) . collect ( ) ;
46
+ // or https://doc.rust-lang.org/std/collections/struct.HashSet.html#method.symmetric_difference
47
+ let diff: HashSet < & char > = t_chars. difference ( & s_chars) . collect ( ) ;
48
+ * ( diff. into_iter ( ) . collect :: < Vec < & char > > ( ) [ 0 ] )
48
49
}
49
50
}
50
51
You can’t perform that action at this time.
0 commit comments