id 1400308890 Time: 0 ms MemUsage: 2.8 MB

This commit is contained in:
2024-09-30 13:38:38 +09:00
parent 21e4a2b9ad
commit 6622307389

View 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)
}
}
}
}
}