diff --git a/leetcode/remove-duplicates-from-sorted-list/solution_1394286221.rs b/leetcode/remove-duplicates-from-sorted-list/solution_1394286221.rs new file mode 100644 index 0000000..ae2870e --- /dev/null +++ b/leetcode/remove-duplicates-from-sorted-list/solution_1394286221.rs @@ -0,0 +1,37 @@ +// Definition for singly-linked list. +// #[derive(PartialEq, Eq, Clone, Debug)] +// pub struct ListNode { +// pub val: i32, +// pub next: Option> +// } +// +// impl ListNode { +// #[inline] +// fn new(val: i32) -> Self { +// ListNode { +// next: None, +// val +// } +// } +// } +impl Solution { + pub fn delete_duplicates(mut head: Option>) -> Option> { + 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 + } +} \ No newline at end of file