# 83. Remove Duplicates from Sorted List(Linked List-Easy)

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.

Language : c

```/**
* struct ListNode {
*     int val;
*     struct ListNode *next;
* };
*/
struct ListNode* deleteDuplicates(struct ListNode* head) {
struct ListNode* cur = (int *)malloc(sizeof(struct ListNode));
while(cur != NULL){
while(cur->next != NULL && cur->val == cur->next->val){
cur->next = cur->next->next;
}
cur = cur->next;
}
}```

Language : cpp

```/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
while(cur != NULL){
while(cur->next != NULL && cur->val == cur->next->val){
cur->next = cur->next->next;
}
cur = cur->next;
}
}
};```

Language : python

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

class Solution(object):
"""
:rtype: ListNode
"""

return now```

0 条评论

## 相关文章

### Leetcode 61 Rotate List

Given a list, rotate the list to the right by k places, where k is non-negative...

20910

1042

1062

2106

722

### 21. Merge Two Sorted Lists(Linked List-Easy)

Merge two sorted linked lists and return it as a new list. The new list should b...

19110

### Leetcode 21 Merge Two Sorted Lists

Merge two sorted linked lists and return it as a new list. The new list should b...

2099

### 链表逆序

1.构造5个节点a,b,c,d,e,并对它们进行初始化； 2.将a,b,c,d,e,5个节点连接在一起

1004