File tree 2 files changed +63
-0
lines changed
2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,40 @@ public:
169
169
};
170
170
```
171
171
172
+ ### ** Rust**
173
+
174
+ ``` rust
175
+ // Definition for singly-linked list.
176
+ // #[derive(PartialEq, Eq, Clone, Debug)]
177
+ // pub struct ListNode {
178
+ // pub val: i32,
179
+ // pub next: Option<Box<ListNode>>
180
+ // }
181
+ //
182
+ // impl ListNode {
183
+ // #[inline]
184
+ // fn new(val: i32) -> Self {
185
+ // ListNode {
186
+ // next: None,
187
+ // val
188
+ // }
189
+ // }
190
+ // }
191
+ impl Solution {
192
+ pub fn delete_node (mut head : Option <Box <ListNode >>, val : i32 ) -> Option <Box <ListNode >> {
193
+ let mut cur = & mut head ;
194
+ while let Some (node ) = cur {
195
+ if node . val == val {
196
+ * cur = node . next. take ();
197
+ break ;
198
+ }
199
+ cur = & mut cur . as_mut (). unwrap (). next;
200
+ }
201
+ head
202
+ }
203
+ }
204
+ ```
205
+
172
206
### ** ...**
173
207
174
208
```
Original file line number Diff line number Diff line change
1
+ // Definition for singly-linked list.
2
+ // #[derive(PartialEq, Eq, Clone, Debug)]
3
+ // pub struct ListNode {
4
+ // pub val: i32,
5
+ // pub next: Option<Box<ListNode>>
6
+ // }
7
+ //
8
+ // impl ListNode {
9
+ // #[inline]
10
+ // fn new(val: i32) -> Self {
11
+ // ListNode {
12
+ // next: None,
13
+ // val
14
+ // }
15
+ // }
16
+ // }
17
+ impl Solution {
18
+ pub fn delete_node ( mut head : Option < Box < ListNode > > , val : i32 ) -> Option < Box < ListNode > > {
19
+ let mut cur = & mut head;
20
+ while let Some ( node) = cur {
21
+ if node. val == val {
22
+ * cur = node. next . take ( ) ;
23
+ break ;
24
+ }
25
+ cur = & mut cur. as_mut ( ) . unwrap ( ) . next ;
26
+ }
27
+ head
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments