Remove Duplicates from Sorted List
来源:互联网 发布:御彩轩计划软件下载 编辑:程序博客网 时间:2024/06/07 12:14
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 * pre =head; ListNode * cur = head->next; while(cur!=NULL){ if(pre->val==cur->val){ cur = cur -> next; free(pre->next); pre->next=cur; } else{ pre = cur; cur = cur->next; } } return head; }};
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
- 安装MariaDB
- TLS协议分析 (八) 实现与开源项目
- Java 面试知识点2
- Interface Orientation
- 廖雪峰还是挺靠谱的
- Remove Duplicates from Sorted List
- 欢迎使用CSDN-markdown编辑器
- JAVA NIO之Buffer(一)
- Webpack对比其他框架的优势分析
- ctrl左键无效
- SHOW PROCESSLIST ,mysql进程查询和定时脚本零时解决进程锁死问题
- iOS中使用textView进行图文混排的上传与显示
- IOS开发第二天-类别与扩展
- CDR怎么保存JPG格式