83. Remove Duplicates from Sorted List Easy
1/**
2 * [83] Remove Duplicates from Sorted List
3 *
4 * Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.
5 *
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/04/list1.jpg" style="width: 302px; height: 242px;" />
8 * Input: head = [1,1,2]
9 * Output: [1,2]
10 *
11 * Example 2:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/04/list2.jpg" style="width: 542px; height: 222px;" />
13 * Input: head = [1,1,2,3,3]
14 * Output: [1,2,3]
15 *
16 *
17 * Constraints:
18 *
19 * The number of nodes in the list is in the range [0, 300].
20 * -100 <= Node.val <= 100
21 * The list is guaranteed to be sorted in ascending order.
22 *
23 */
24pub struct Solution {}
25use crate::util::linked_list::{ListNode, to_list};
26
27// problem: https://leetcode.com/problems/remove-duplicates-from-sorted-list/
28// discuss: https://leetcode.com/problems/remove-duplicates-from-sorted-list/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32// Definition for singly-linked list.
33// #[derive(PartialEq, Eq, Clone, Debug)]
34// pub struct ListNode {
35// pub val: i32,
36// pub next: Option<Box<ListNode>>
37// }
38//
39// impl ListNode {
40// #[inline]
41// fn new(val: i32) -> Self {
42// ListNode {
43// next: None,
44// val
45// }
46// }
47// }
48impl Solution {
49 pub fn delete_duplicates(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
50 Some(Box::new(ListNode::new(0)))
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_83() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.