Remove Duplicates from Sorted List
来源:互联网 发布:酷狗音乐无法使用网络 编辑:程序博客网 时间:2024/04/29 16: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.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
package leetcode;class ListNode { int val; ListNode next; ListNode(int x) { val = x; next = null; }}public class RemoveDuplicatesFromSortedList {public ListNode deleteDuplicates(ListNode head) {if(head == null) return null;ListNode cur = head;ListNode next = head.next;while(true){if(next == null) {cur.next = null; break;}if(cur.val == next.val) next = next.next;else {cur.next = next;cur = next;next = cur.next;}} return head; }}
0 0
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove duplicates from sorted list
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Binary Tree Inorder Traversal
- wordpress 获取分类的顶级父类
- Populating Next Right Pointers in Each Node
- 验证身份证号方法
- JavaScript相关术语
- Remove Duplicates from Sorted List
- Single Number II
- Climbing Stairs
- Search Insert Position
- Roman to Integer
- Maximum Subarray
- 个人玩儿温柔温柔
- Apache 门户项目组介绍
- Maximum Subarray