83. Remove Duplicates from Sorted List
来源:互联网 发布:绿色建筑设计软件 编辑:程序博客网 时间:2024/06/04 18:55
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) return head; ListNode* pre=head; ListNode* after=pre->next; while(after!=NULL) { while(after!=NULL) { if(after->val==pre->val) after=after->next; else break; } pre->next=after; pre=after; } return head; }};
阅读全文
0 0
- [LeetCode]83.Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- [Leetcode] 83. Remove Duplicates from Sorted List
- LeetCode --- 83. Remove Duplicates from Sorted List
- [leetcode] 83.Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- 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 LeetCode
- 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
- [LeetCode]83. Remove Duplicates from Sorted List
- 【LeetCode】83. Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- DELPHI窗体属性介绍
- python之numpy学习
- Retrofit的使用与基本的封装
- 使用 python 读取 json 文件
- 每天60s轻松搞定PHP之10个不可不知的小事项
- 83. Remove Duplicates from Sorted List
- offset分析
- 冒泡排序与选择排序区别
- daemon 需要fork两次原因
- Spark性能优化:开发调优篇
- shared ptr
- 全选反选
- github的一些使用指南
- golang编辑器 Idea IntelliJ