Remove Duplicates from Sorted List
来源:互联网 发布:软件界面图片素材 编辑:程序博客网 时间:2024/05/16 07:16
Remove Duplicates from Sorted List
Total Accepted: 2906 Total Submissions: 8626My SubmissionsGiven 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) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. if(head == NULL) return NULL; ListNode *cur = head, *nextNode = head->next; while(nextNode != NULL){ if(cur->val == nextNode->val){ cur->next = nextNode->next; delete nextNode; nextNode = cur->next; } else { cur = cur->next; nextNode = nextNode->next; } } return head; }};
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove duplicates from sorted list
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- 程序员的职业规划
- uva193继续回溯!!
- 硕博经验——科研论文阅读与写作实战技巧
- 软链接和硬链接
- 观察者模式
- Remove Duplicates from Sorted List
- 【转】WINDOWS IO完成端口的一些内部细节理解
- 答一名大三同学的信——我该不该做项目
- UVA11462-(Age sort)(计数排序)
- POJ 1275 Cashier Employment
- 要考研,先要做到不比钱
- Problem 2091 播放器 模拟问题 I never stop loving you, but I just don't want anybody to see it any more.
- Data Structure(with C).Experiment01.02
- 写科研论文的高级方法学