id 1394286221 Time: 2 ms MemUsage: 2.1 MB
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// 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 delete_duplicates(mut head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
|
||||
let mut curr_opt = head.as_mut();
|
||||
|
||||
while let Some(curr) = curr_opt {
|
||||
let mut check_opt = curr.next.take();
|
||||
|
||||
while let Some(check) = check_opt.as_mut() {
|
||||
if check.val == curr.val {
|
||||
check_opt = check.next.take();
|
||||
}
|
||||
else {
|
||||
curr.next = check_opt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
curr_opt = curr.next.as_mut();
|
||||
}
|
||||
head
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user