LeetCode-Easy刷题(17) Remove Duplicates from Sorted List
来源:互联网 发布:上海重庆火锅 知乎 编辑:程序博客网 时间:2024/05/29 07:38
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
.
删除排好序链表中重复的数字.返回一个数字不重复的链表
//链表指针控制 双指针 public ListNode deleteDuplicates(ListNode head) { if(head ==null){ return head; } ListNode helper = new ListNode(0); ListNode pre = helper; pre.next = head; while(head.next!=null){ ListNode next = head.next; if(head.val != next.val){ pre.next.next = next; pre = pre.next; } head = next; } if(pre.next.next!=null){ pre.next.next=null;; } return helper.next; }
阅读全文
0 0
- LeetCode-Easy刷题(17) Remove Duplicates from Sorted List
- [Leetcode 83, easy] Remove Duplicates from Sorted List
- <LeetCode><Easy> 83 Remove Duplicates from Sorted List
- Leetcode 83. Remove Duplicates from Sorted List (Easy) (cpp)
- 【leetcode】 83. Remove Duplicates from Sorted List(easy)
- 83. Remove Duplicates from Sorted List (Easy)
- Easy-题目17:83. Remove Duplicates from Sorted List
- LeetCode刷题(C++)——Remove Duplicates from Sorted List(Easy)
- LeetCode-Easy刷题(7) Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted List :from LeetCode
- Leetcode - List - Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List
- [Leetcode] Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List
- 两个栈实现一个队列和两个队列实现一个栈
- 数据结构-循环双链表
- 服务器上的 Git
- 乐观锁和悲观锁的区别
- hdu3572-Task Schedule(最大流(ISAP),是否满流)
- LeetCode-Easy刷题(17) Remove Duplicates from Sorted List
- 服务器上的 Git
- LeetCode-Easy刷题(18) Merge Sorted Array
- ACM刷题狗的心路历程2
- 日刷(距上次好像5天了) Uva10881
- 异常处理
- LeetCode-Easy刷题(19) Same Tree
- es6中的模块化
- PHP 数据库,读取数据集中数据的三种方法