id 1400308890 Time: 0 ms MemUsage: 2.8 MB
This commit is contained in:
31
leetcode/remove-linked-list-elements/solution_1400308890.rs
Normal file
31
leetcode/remove-linked-list-elements/solution_1400308890.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
// Definition for singly-linked list.
|
||||
// #[derive(PartialEq, Eq, Clone, Debug)]
|
||||
// pub struct ListNode {
|
||||
// pub val: i32,
|
||||
// pub next: Option<Box<ListNode>>
|
||||
// }
|
||||
//
|
||||
// impl ListNode {
|
||||
// #[inline]
|
||||
// fn new(val: i32) -> Self {
|
||||
// ListNode {
|
||||
// next: None,
|
||||
// val
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
impl Solution {
|
||||
pub fn remove_elements(mut head: Option<Box<ListNode>>, val: i32) -> Option<Box<ListNode>> {
|
||||
match head{
|
||||
None => None,
|
||||
Some(mut node) => {
|
||||
if node.val == val{
|
||||
Self::remove_elements(node.next, val)
|
||||
} else {
|
||||
node.next = Self::remove_elements(node.next, val);
|
||||
Some(node)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user