FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_01/id_16/LeetCode_83_16.cpp at master · feixiangcode/algorithm · GitHub
feixiangcode
/
algorithm
Public
forked from
algorithm001/algorithm
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
Week_01
/
id_16
/
LeetCode_83_16.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (39 loc) · 1.06 KB
Breadcrumbs
algorithm
/
Week_01
/
id_16
/
LeetCode_83_16.cpp
Copy path
File metadata and controls
42 lines (39 loc) · 1.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
*[链表][简单]
给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
示例 1:
输入: 1->1->2
输出: 1->2
示例 2:
输入: 1->1->2->3->3
输出: 1->2->3
*/
/*
个人感悟:
指针的使用要好好琢磨
*/
/*
思路1:由于输入的列表已排序,因此我们可以通过将结点的值与它之后的结点进行比较来确定它是否为重复结点。
如果它是重复的,我们更改当前结点的 next 指针,以便它跳过下一个结点并直接指向下一个结点之后的结点。
*/
/*
*
* 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) {
ListNode* current = head;
while
(current && current->
next
){
if
(current->
val
== current->
next
->
val
){
current->
next
= current->
next
->
next
;
}
else
{
current = current->
next
;
}
}
return
head;
}
};
Back
|
FazBrowse Home
|
New Git URL