83. Remove Duplicates from Sorted List
2017-08-18 14:54
274 查看
/* 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; * struct ListNode *next; * }; */ struct ListNode* deleteDuplicates(struct ListNode* head){ if(!head || !head->next) return head; struct ListNode *fast=head; while(fast) { if(fast->next && fast->val==fast->next->val) { fast->next=fast->next->next; } else fast=fast->next; } return head; }
相关文章推荐
- 83. Remove Duplicates from Sorted List
- Leetcode:83. Remove Duplicates from Sorted List(JAVA)
- 83. Remove Duplicates from Sorted List
- LeetCode笔记:83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- Easy-题目17:83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List (链表)
- 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List--LeetCode Record
- leecode 解题总结:83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List