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