Leetcode题解 83. Remove Duplicates from Sorted List
来源:互联网 发布:帝国坟场 阿富汗 知乎 编辑:程序博客网 时间:2024/05/23 18:59
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.
用《剑指offer》的“删除链表中某个节点”的方法来做这道题即可。
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { public ListNode deleteDuplicates(ListNode head) { if(head==null){ return head; }else if(head.next==null){ return head; } ListNode temp=head; ListNode next=head.next; while(next.next!=null){ if(head.val==next.val){ next.val=next.next.val; next.next=next.next.next; }else{ head=head.next; next=next.next; } } if(head.val==next.val){ head.next=null; } return temp; }}
0 0
- LeetCode题解:Remove Duplicates from Sorted List
- LeetCode题解: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
- [LeetCode]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
- LeetCode 83. Remove Duplicates from Sorted List
- 【leetcode】83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List LeetCode
- leetcode 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
- [leetcode] 83. Remove Duplicates from Sorted List
- leetcode 83. Remove Duplicates from Sorted List
- 正则表达式 - 元字符
- HBuilder webApp开发(七)微信/QQ/新浪/腾讯微博分享
- Problem H: 2.4.5 Fractions to Decimals 分数化小数
- 正则表达式 - 运算符优先级
- 【t1】·badboy跟jmeter结合的网页参数化测试(pigeon详细说)
- Leetcode题解 83. Remove Duplicates from Sorted List
- (UVA)1587Box
- WAMPServer更改web根目录
- 咖啡图库
- Swift通过类名创建对象
- 正则表达式 - 匹配规则
- LeetCode题解-82-Remove Duplicates from Sorted List II
- 策略模式(Strategy) Java 计算器加减法抽象
- (二)JavaScript中的面对对象