-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdeleteDuplicates.h
More file actions
43 lines (36 loc) · 979 Bytes
/
deleteDuplicates.h
File metadata and controls
43 lines (36 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// deleteDuplicates.h
// linkedList
//
// Created by junlongj on 2019/8/10.
// Copyright © 2019 junl. All rights reserved.
//
#ifndef deleteDuplicates_hpp
#define deleteDuplicates_hpp
#include <stdio.h>
/*
给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
示例 1:
输入: 1->1->2
输出: 1->2
示例 2:
输入: 1->1->2->3->3
输出: 1->2->3
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
*/
namespace leetcode {
ListNode* deleteDuplicates(ListNode* head) {
ListNode *ct=head;
while(ct && ct->next){
if (ct->val == ct->next->val){
ct->next=ct->next->next;
}else{
ct=ct->next;
}
}
return head;
}
}
#endif /* deleteDuplicates_hpp */