Remove Duplicates from Sorted List
来源:互联网 发布:淘宝网最小手机 编辑:程序博客网 时间:2024/06/05 18:12
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode deleteDuplicates(ListNode head) { if(head == null) { return head; } ListNode prev = head, curr = head.next; for( ; curr != null; curr = curr.next) { if(curr.val != prev.val) { prev.next = curr; prev = curr; } } prev.next = null; return head; }}
Time: O(n)
Space: O(1)
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
- Java 5|6 并发包介绍
- 另眼相看“那些争议最大的编程观点”
- Python 提取Twitter特定话题中转载tweet的用户
- 软件架构设计和概要设计
- Partition List
- Remove Duplicates from Sorted List
- 高并发策略实例分析
- 3.3 String to Integer(atoi)
- Visual Prolog 的 Web 专家系统 (2)
- 推荐一些设计素材(持续更新,频率不定)
- [LeetCode]Flatten Binary Tree to Linked List
- spring中ClassPathXmlApplicationContext和FileSystemXmlApplicationContext的路径问题
- Ruby知识积累1
- Person p=new Person()的感悟