LeetCode 83. Remove Duplicates from Sorted List
83. 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.
/**
* 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 == NULL || head->next == NULL) {
return head;
}
ListNode *p = head;
while(p != NULL && p->next != NULL) {
while (p->next != NULL && p->next->val == p->val) {
p->next = p->next->next;
}
p = p->next;
}
return head;
}
};
相關文章
- 83. Remove Duplicates from Sorted ListREM
- 【Leetcode】83. Remove Duplicates from Sorted ListLeetCodeREM
- Leetcode Remove Duplicates from Sorted ListLeetCodeREM
- Remove Duplicates from Sorted ListREM
- Leetcode Remove Duplicates from Sorted List IILeetCodeREM
- Leetcode-Remove Duplicates from Sorted ListLeetCodeREM
- Remove Duplicates from Sorted List leetcode javaREMLeetCodeJava
- Remove-duplicates-from-sorted-listREM
- Leetcode-Remove Duplicates from Sorted List IILeetCodeREM
- Remove Duplicates from Sorted List II leetcode javaREMLeetCodeJava
- 【Leetcode】82. Remove Duplicates from Sorted List IILeetCodeREM
- 82. Remove Duplicates from Sorted List IIREM
- leetcode Remove Duplicates from Sorted ArrayLeetCodeREM
- Leetcode 26 Remove Duplicates from Sorted ArrayLeetCodeREM
- Leetcode Remove Duplicates from Sorted Array IILeetCodeREM
- Leetcode-Remove Duplicates from Sorted ArrayLeetCodeREM
- Remove Duplicates from Sorted Array leetcode javaREMLeetCodeJava
- 【LeetCode從零單排】No83 Remove Duplicates from Sorted ListLeetCodeREM
- [leetcode]remove-duplicates-from-sorted-array-iiLeetCodeREM
- Leetcode-Remove Duplicates from Sorted Array IILeetCodeREM
- Remove Duplicates from Sorted Array II leetcode javaREMLeetCodeJava
- Remove-duplicates-from-sorted-arrayREM
- [LeetCode] 80. Remove Duplicates from Sorted Array IILeetCodeREM
- 26. Remove Duplicates from Sorted ArrayREM
- 【LeetCode從零單排】No26.Remove Duplicates from Sorted ArrayLeetCodeREM
- Remove Duplicates from Sorted List 去除連結串列中重複值節點REM
- LeetCode 83.Remove Duplicates from Sorted List(從已排序連結串列中除去重複) Easy/Linked ListLeetCodeREM排序
- [LeetCode] Remove Duplicates from Sorted Array 有序陣列中去除重複項LeetCodeREM陣列
- 【leetcode】26. Remove Duplicates from Sorted Array 刪除有序陣列的重複元素LeetCodeREM陣列
- Leetcode Remove Nth Node From End of ListLeetCodeREM
- Leetcode 19 Remove Nth Node From End of ListLeetCodeREM
- Leetcode-Remove Nth Node From End of ListLeetCodeREM
- Remove Nth Node From End of List leetcode javaREMLeetCodeJava
- leetcode19:Remove Nth Node From End of ListLeetCodeREM
- [LeetCode] 2487. Remove Nodes From Linked ListLeetCodeREM
- [CareerCup] 2.1 Remove Duplicates from Unsorted List 移除無序連結串列中的重複項REM
- 19. Remove Nth Node From End of ListREM
- LeetCode Remove Nth Node From End of List(019)解法總結LeetCodeREM