File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,10 @@ impl ListNode {
31
31
impl Solution {
32
32
pub fn remove_elements (head : Option <Box <ListNode >>, val : i32 ) -> Option <Box <ListNode >> {
33
33
let mut head = Some (Box :: new (ListNode { val : 0 , next : head }));
34
- let mut a = & mut head ;
34
+ let mut a : & mut Option < Box < ListNode >> = & mut head ;
35
35
while a . as_deref_mut (). unwrap (). next. is_some () {
36
+ // ^ Option<&mut ListNode>
37
+ //
36
38
let v = a . as_deref_mut (). unwrap (). next. as_deref (). unwrap (). val;
37
39
if v == val {
38
40
let mut b = a . as_deref_mut (). unwrap (). next. take ();
@@ -48,7 +50,9 @@ impl Solution {
48
50
}
49
51
```
50
52
51
- 属实有点恶心了
53
+ 属实有点恶心了,看着太复杂了,这就是不用take的后果
54
+
55
+
52
56
53
57
## 学习感想
54
58
@@ -135,4 +139,8 @@ impl Solution {
135
139
res
136
140
}
137
141
}
138
- ```
142
+ ```
143
+
144
+ 链表的ownership还是非常容易理清楚的
145
+
146
+ 一个Option不是owner没法直接unwrap,但是as_mut了之后可以随意unwrap,这也是容器穿透
You can’t perform that action at this time.
0 commit comments