Remove Duplicates from Sorted List
来源:互联网 发布:mac上好用的邮箱软件 编辑:程序博客网 时间:2024/06/04 00:27
/** * 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) return head; ListNode *head1 = head; int pre = head->val; while(head->next != NULL) { ListNode *temp = head; head = head->next; if(head->val == pre) { temp->next = temp->next->next; head = temp; } else pre = head->val; } return head1; }};
问题比较简单,保存相似节点的第一个值,然后遍历链表,若后一节点与当前节点值
相同则删除此节点,若不是则跟新这个标准值
0 0
- 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
- C++学习日记之对象作为数据成员
- 谈谈android反编译和防止反编译的方法
- SVN 文件已锁定解决方法
- JavaScript 全局函数
- 空指针异常,可自己找不到问题的所在,谁能帮下我?
- Remove Duplicates from Sorted List
- JSP自定义标签开发入门
- Wifi共享精灵2014.3.17版怎么样?
- R语言之作者合作网络jaccard系数及余弦相似性实现篇
- 呦嘿!~
- Android中的消息机制
- 算法学习八----约瑟夫问题
- 网络营销的市场在哪里?
- Delphi报表控件QuickReport VS FastReport对比