[LeetCode]83. 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.
设置2个指针,cur 和next。
当cur的值与next的值相等时,cur.next= next.next 更新next = next.next;
当cur的值与next的值不等时,cur = next 更新next = next.next;
public class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head == null ||head.next == null) return head;
ListNode cur = head;
ListNode next = head.next;
while(next != null){
if(cur.val == next.val)
cur.next = next.next;
else cur = next;
next = next.next;
}
return head;
}
[LeetCode]83. Remove Duplicates from Sorted List(排序链表去重)的更多相关文章
- [leetcode]83. Remove Duplicates from Sorted List有序链表去重
Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...
- [LeetCode] 83. Remove Duplicates from Sorted List 移除有序链表中的重复项
Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...
- [LeetCode] 83. Remove Duplicates from Sorted List ☆(从有序链表中删除重复项)
描述 Given a sorted linked list, delete all duplicates such that each element appear only once. Exampl ...
- leetCode 83.Remove Duplicates from Sorted List(删除排序链表的反复) 解题思路和方法
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- LeetCode 83. Remove Duplicates from Sorted List (从有序链表中去除重复项)
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- Java [Leetcode 83]Remove Duplicates from Sorted List
题目描述: Given a sorted linked list, delete all duplicates such that each element appear only once. For ...
- [LeetCode] 83. Remove Duplicates from Sorted List_Easy tag: Linked List
Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...
- Leetcode 83 Remove Duplicates from Sorted List 链表
就是将链表中的重复元素去除 我的方法很简单就是如果链表的前后元素相同的话,将后一个元素删除 /** * Definition for singly-linked list. * struct List ...
- LeetCode 83. Remove Duplicates from Sorted List(从有序链表中删除重复节点)
题意:从有序链表中删除重复节点. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode ...
随机推荐
- weblogic11g重置控制密码
Reset the AdminServer Password in WebLogic 11g and 12c If you forget the AdminServer password for yo ...
- PyQt4关闭窗口
一个显而易见的关闭窗口的方式是但集标题兰有上角的X标记.接下来的示例展示如何用代码来关闭程序,并简要介绍Qt的信号和槽机制. 下面是QPushButton的构造函数,我们将会在下面的示例中使用它. Q ...
- Spring学习笔记--自动装配Bean属性
Spring提供了四种类型的自动装配策略: byName – 把与Bean的属性具有相同名字(或者ID)的其他Bean自动装配到Bean的对应属性中. byType – 把与Bean的属性具有相同类型 ...
- 元素设置disabled属性后便无法向后台传值
元素设置disabled属性后便无法向后台传值
- mount: block device /dev/cdrom is write-protected, mounting read-only 解决方法
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/ mount: block device /dev/sr0 is write-protected, mo ...
- 原生JS,实现图片可拖拽,并且移动四个角和四条变能够自由变换图片大小
网上搜的资料,源码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- 2.6 CMMI2级——供应商协议管理(Supplier Agreement Management)
做软件开发的,不免要购买一些软硬件.软件可能是中间件.控件.插件.组件等,硬件可能是一些服务器.PDA.单片机等.只要稍微复杂的项目,都不可避免的会有采购的问题,就算目前没有采购,以后也会不可避免.另 ...
- 【linux系列】linux防火墙的关闭开启
即时生效 开启:service iptables start 关闭:service iptables stop 重启后生效 开启:chkconfig iptables on 关闭:chkconfig ...
- Android 动画fillAfter和fillBefore
fillBefore是指动画结束时画面停留在此动画的第一帧; fillAfter是指动画结束是画面停留在此动画的最后一帧. Java代码设置如下: /*****动画结束时,停留在最后一帧******* ...
- Windows Phone WebClient的使用
webClient对象可用来下载XML文件,程序集等这些数据,其可以实现按需下载,所以还是有必要了解的.其主要包含几个事件: ...