LeetCode83 Remove Duplicates from Sorted List
2017-10-15 21:11
435 查看
LeetCode83 Remove Duplicates from Sorted List
问题链接 LeetCode83问题描述
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 myHead = new ListNode(-1); myHead.next = head; while(head.next!=null){ if(head.val==head.next.val){ head.next = head.next.next; }else{ head = head.next; } } return myHead.next; } // class ListNode { // int val; // ListNode next; // ListNode(int x) { val = x; } // }
LeetCode学习笔记持续更新
GitHub地址 https://github.com/yanqinghe/leetcode
CSDN博客地址 http://blog.csdn.net/yanqinghe123/article/category/7176678
相关文章推荐
- LeetCode 83 - Remove Duplicates from Sorted List
- 【leetcode】【单链表】【83】Remove Duplicates from Sorted List
- Leetcode 83 Remove Duplicates from Sorted List
- [Leetcode 83, easy] Remove Duplicates from Sorted List
- LeetCode 83:Remove Duplicates from Sorted List
- Leetcode 83 Remove Duplicates from Sorted List 有序链表去重
- Java [Leetcode 83]Remove Duplicates from Sorted List
- leetcode-Remove Duplicates from Sorted List-83
- LeetCode 83 Remove Duplicates from Sorted List
- leetcode 83 Remove Duplicates from Sorted List
- LeetCode 83 Remove Duplicates from Sorted List II
- leetcode: (83) Remove Duplicates from Sorted List
- LeetCode 83 — Remove Duplicates from Sorted List(C++ Java Python)
- LeetCode(83)Remove Duplicates from Sorted List
- leetcode83:Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List leetcode list
- 【LeetCode】C# 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