[leetcode]83. Remove Duplicates from Sorted List有序链表去重
Given a sorted linked list, delete all duplicates such that each element appear only once.
Example 1:
Input: 1->1->2
Output: 1->2
Example 2:
Input: 1->1->2->3->3
Output: 1->2->3
题意:
有序链表去重
思路:


代码:
class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head == null) return head;
ListNode cur = head;
while(cur.next != null){
if(cur.val == cur.next.val){
cur.next = cur.next.next;
}else{
cur = cur.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. For examp ...
- [leetcode]26. Remove Duplicates from Sorted Array有序数组去重(单个元素只出现一次)
Given a sorted array nums, remove the duplicates in-place such that each element appear only once an ...
- [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] 26. Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array nums, remove the duplicates in-place such that each element appear only once an ...
- LeetCode 83. Remove Duplicates from Sorted List(从有序链表中删除重复节点)
题意:从有序链表中删除重复节点. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode ...
- 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 ...
随机推荐
- Python开发 基礎知識 (未完代補)
一.Python基本知識 1.Python屬高階語言,所編築的是字節碼 2.一般狀態statement 終止於換行,如需使用多數行編寫,可在行末加上 \,以表延續 但在 parentheses ( ) ...
- 登录ssh提示:ssh_exchange_identification: read: Connection reset by peer error
vim /etc/hosts.allow 添加 sshd : ALL
- asp.net core 2.0 后台定时自动执行任务
自己写一个类继承BackgroundService internal class RefreshService : BackgroundService { protected override asy ...
- python中list列表的方法len()
作用:返回列表中元素的个数. 用法: len(list)
- 第六届蓝桥杯省赛 java三羊献瑞
将文字看作一个个变量.根据一开始确定的文字的值进行暴力循环. 三羊献瑞 观察下面的加法算式: 祥 瑞 生 辉 + 三 羊 献 瑞------------------- 三 羊 生 瑞 气 (如果有对齐 ...
- 深度图从ros数据类型转换成opencv数据类型
摘要:ros下,利用realsense D435采集深度图,并将其转换成opencv的数据类型. 一. RGBD图像采集 通过image_transport包,根据给定的采集速度从realsense ...
- 解决ubuntu16.04桌面左侧栏和顶部栏消失的问题
重要事情说三遍! 不要轻易重装系统! 不要轻易重装系统! 不要轻易重装系统! 问题所在:误删了unity桌面. 解决方法: $sudo apt-get install unity
- python永久添加环境变量
import sys sys.path 系统环境是一个list,可以将自己需要的库添加进入,例如mysql库,hive库等等.有三种方式添加,均验证通过: 1 临时添加,在一个shell窗口中 ...
- ubuntu16.04 安装最新版nodejs
ubuntu软件仓库中自带的nodejs版本过低 $ apt-cache policy nodejs nodejs: Installed: (none) Candidate: 4.2.6~dfsg-1 ...
- 学习 MeteoInfo二次开发教程(五)
1.ActiveMapFrame部分没有大问题,按教程来就行. private void SetMapView()和private void ActiveMapFrameChanged(object ...