Easy-题目17:83. Remove Duplicates from Sorted List
来源:互联网 发布:遗传算法c程序 编辑:程序博客网 时间:2024/05/21 11:37
题目原文:
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.
题目大意:
给出一个排序的单链表,删除所有重复元素使得每个元素仅出现一次。
题目分析:
判断当前节点的值是否等于其后继节点,若等于则删除后继节点(p->next=p->next->next),否则当前节点向右移动(p=p->next)。
源码:(language:c)
struct ListNode* deleteDuplicates(struct ListNode* head) { struct ListNode* p = head; if(!head) return; while(p->next) { if(p->val == p->next->val) p->next=p->next->next; else p=p->next; } return head;}
成绩:
4ms,beats 10.82%,众数4ms,89.18%
0 0
- Easy-题目17:83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List (Easy)
- 83. Remove Duplicates from Sorted List(Linked List-Easy)
- 83. Remove Duplicates from Sorted List [easy] (Python)
- Leetcode 83. Remove Duplicates from Sorted List (Easy) (cpp)
- 【leetcode】 83. Remove Duplicates from Sorted List(easy)
- LeetCode-Easy刷题(17) Remove Duplicates from Sorted List
- Easy-题目29:26. Remove Duplicates from Sorted Array
- [Leetcode 83, easy] Remove Duplicates from Sorted List
- <LeetCode><Easy> 83 Remove Duplicates from Sorted List
- Easy 18 Remove Duplicates from Sorted List(83)
- [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
- <SeekBar>拖动条的 简单功能与用法
- GIT
- Dwarf Error: wrong version in compilation unit header (is 4, should be 2)
- Easy-题目16:328. Odd Even Linked List
- Mysql中Group By使用Having语句配合查询
- Easy-题目17:83. Remove Duplicates from Sorted List
- QT--helloworld
- [JavaScript] 9.JS DOM模型
- 网页中DIV无法正常显示的问题
- 夜间模式的实现
- shell脚本打印日志方法
- c# MD5的加密和解密
- 职业生涯的 思考
- Easy-题目18:70. Climbing Stairs