# 83.Remove Duplicates from Sorted List

**83.Remove Duplicates from Sorted List**

难度:Easy

> 给定一个排序链表，删除所有重复的元素，使得每个元素只出现一次。

```
示例 1:

输入: 1->1->2
输出: 1->2
示例 2:

输入: 1->1->2->3->3
输出: 1->2->3
```

使用快慢指针。

```
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        if(!head) return head;
        ListNode* root=head;
        ListNode* fast=head->next;
        while(fast)
        {
            if(root->val == fast->val)
            {
                root->next = fast->next;
                fast=fast->next;
            }
            else
            {
                root=root->next;
                fast=fast->next;
            }
        }
        return head;
    }
};
```

> 执行用时 :20 ms, 在所有 C++ 提交中击败了76.86%的用户\
> 内存消耗 :9.2 MB, 在所有 C++ 提交中击败了48.46%的用户


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/83.remove_duplicates_from_sorted_list.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
