File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -40,4 +40,27 @@ impl Solution {
40
40
```
41
41
## 学习感想
42
42
43
- 一下子不知道怎么做,但是把false的例子弄明白就知道了
43
+ 一下子不知道怎么做,但是把false的例子弄明白就知道了
44
+
45
+
46
+ ``` rust
47
+ # struct Solution {}
48
+
49
+ impl Solution {
50
+ pub fn is_happy (mut n : i32 ) -> bool {
51
+ use std :: collections :: HashSet ;
52
+ let mut set : HashSet <i32 > = HashSet :: from ([n ]);
53
+ loop {
54
+ let mut new = 0i32 ;
55
+ while n != 0i32 {
56
+ new += (n % 10i32 ). pow (2u32 );
57
+ n /= 10i32 ;
58
+ }
59
+ if new == 1i32 { break true }
60
+ if set . contains (& new ) { break false }
61
+ set . insert (new );
62
+ n = new ;
63
+ }
64
+ }
65
+ }
66
+ ```
Original file line number Diff line number Diff line change @@ -33,9 +33,10 @@ impl Solution {
33
33
impl Solution {
34
34
pub fn intersection (nums1 : Vec <i32 >, nums2 : Vec <i32 >) -> Vec <i32 > {
35
35
use std :: collections :: HashSet ;
36
- let set1 : HashSet <i32 > = HashSet :: from_iter (nums1 . into_iter ());
37
- let set2 : HashSet <i32 > = HashSet :: from_iter (nums2 . into_iter ());
38
- set1 . intersection (& set2 ). map (| & x | x ). collect ()
36
+ let set1 : HashSet <i32 > = HashSet :: from_iter (nums1 );
37
+ let set2 : HashSet <i32 > = HashSet :: from_iter (nums2 );
38
+ // set1.intersection(&set2).map(|&x| x).collect()
39
+ set1 . intersection (& set2 ). copied (). collect ()
39
40
}
40
41
}
41
42
You can’t perform that action at this time.
0 commit comments