Skip to content

Commit cc7838a

Browse files
committed
1
1 parent fa98507 commit cc7838a

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

notes/src/day6/lc202.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,27 @@ impl Solution {
4040
```
4141
## 学习感想
4242

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+
```

notes/src/day6/lc349.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ impl Solution {
3333
impl Solution {
3434
pub fn intersection(nums1: Vec<i32>, nums2: Vec<i32>) -> Vec<i32> {
3535
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()
3940
}
4041
}
4142

0 commit comments

Comments
 (0)