LeetCode-Remove Duplicates from Sorted List
来源:互联网 发布:手机淘宝购物付款方式 编辑:程序博客网 时间:2024/05/29 16:39
题目:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/
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
.
算法分析:时间复杂度O(n),空间复杂度O(1)
/** * 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 null; } ListNode node=head.next; ListNode newNode=head; while(node!=null) { if(node.val!=newNode.val) { newNode.next=node; newNode=node; } node=node.next; } newNode.next=null; return head; }}
0 0
- 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
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- leetcode 37: Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode]Remove Duplicates from Sorted List
- 更改SQL Server服务密码
- 二叉排序树
- 数据库之提取信息
- Reading Notes:《如何阅读一本书》
- 数据库之输入信息
- LeetCode-Remove Duplicates from Sorted List
- 创建示例数据库
- 嵌入式 sqlite3中的数据类型
- 数据库入门知识
- 关于setpeer和getpeer的作用
- JDK7新特性
- 创建示例数据库
- MFC COMBO BOX内写入内容
- 数据库之输入信息