# Q83 Remove Duplicates from Sorted List

Given a sorted linked list, delete all duplicates such that each element appear only once.

For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3.

##### Python实现：
```# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
"""
:rtype: ListNode
"""
if cur == None or cur.next == None:  # 如果是空链表或链表只有一个元素
while cur.next != None:
if cur.val == cur.next.val:  # 如果连续两个值相等，则删除后一个
cur.next = cur.next.next
else:  # 如果不相等，当前指针后移
cur = cur.next

161 篇文章42 人订阅

0 条评论

## 相关文章

### LeetCode 203 & 237. Delete Node in a Linked List

Write a function to delete a node (except the tail) in a singly linked list, giv...

1410

1253

1323

1976

### 【左神算法课】超经典：求两单向链表交点（6种情况）

若一个有环一个无环，直接返回NULL，因为如果他们相交，是不可能一个有环一个无环的（图中情况3）；

1572

1363

### LWC 58：725. Split Linked List in Parts

LWC 58：725. Split Linked List in Parts 传送门：725. Split Linked List in Parts Probl...

2148

813

1843

### 两个排序链表合并

LeetCode 21. Merge Two Sorted Lists 已知两个已排序链表头节点指针L1，L2，将这两个链表合并，合并后仍为有序的，返回合并后...

1053