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 {
3131impl Solution {
3232 pub fn remove_elements (head : Option <Box <ListNode >>, val : i32 ) -> Option <Box <ListNode >> {
3333 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 ;
3535 while a . as_deref_mut (). unwrap (). next. is_some () {
36+ // ^ Option<&mut ListNode>
37+ //
3638 let v = a . as_deref_mut (). unwrap (). next. as_deref (). unwrap (). val;
3739 if v == val {
3840 let mut b = a . as_deref_mut (). unwrap (). next. take ();
@@ -48,7 +50,9 @@ impl Solution {
4850}
4951```
5052
51- 属实有点恶心了
53+ 属实有点恶心了,看着太复杂了,这就是不用take的后果
54+
55+
5256
5357## 学习感想
5458
@@ -135,4 +139,8 @@ impl Solution {
135139 res
136140 }
137141}
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