LeetCode-Easy刷题(17) Remove Duplicates from Sorted List
2017-11-29 18:43
375 查看
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given
Given
删除排好序链表中重复的数字.返回一个数字不重复的链表
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; }
相关文章推荐
- leetcode 083 Remove Duplicates from Sorted List(难易度:Easy)
- 【Leetcode】【Easy】Remove Duplicates from Sorted List
- [Leetcode 83, easy] Remove Duplicates from Sorted List
- LeetCode刷题(C++)——Remove Duplicates from Sorted List(Easy)
- Easy-题目17:83. Remove Duplicates from Sorted List
- 【leetcode】Remove Duplicates from Sorted List (easy)
- leetcode 之Remove Duplicates from Sorted List(17)
- Leetcode137: Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- Leetcode[83]-Remove Duplicates from Sorted List
- [Leetcode]Remove Duplicates from Sorted List II
- 【leetcode c++】83 Remove Duplicates from Sorted List
- [LeetCode]Remove Duplicates from Sorted List
- LeetCode | Remove Duplicates from Sorted List II(删除链表中重复结点2)
- leetcode[83]Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List @LeetCode
- leetcode83 Remove Duplicates from Sorted List
- [LeetCode][Java] Remove Duplicates from Sorted List II
- LeetCode | Remove Duplicates from Sorted List II
- leetcode[82] Remove Duplicates from Sorted List II