LeetCode83.删除排序链表中的重复的元素
2024-08-29 00:57:50
给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
示例 1:
输入: 1->1->2
输出: 1->2
示例 2:
输入: 1->1->2->3->3
输出: 1->2->3
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode deleteDuplicates(ListNode head) {
if (head == null || head.next == 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;
}
}
最新文章
- [WCF编程]12.事务:服务事务编程(下)
- Mac Pro 资源管理器 Double Commander“个性化设置” 备份
- React Native IOS源码初探
- Kotlin从入门到掉坑里
- 再说linux中的rm mv 遍历执行多个文件的操作: find + xagrs
- jsp_设置错误页
- ubuntu下matplotlib画图中文乱码问题
- 【转】 (C#)利用Aspose.Cells组件导入导出excel文件
- 关于Ionic的安装
- HDU 2102 A计划(DFS)
- android登录实现,存储数据到/data/data/包名/info.txt
- 8. Security-oriented operating systems (面向安全的操作系统 5个)
- Discuz!X 3.4 前台任意文件删除漏洞复现
- Python基础05_str_补充
- ads查询结果中文显示方框问题
- HTTP是什么?,GET与POST区别?
- 5月23日——SPA单页面应用的原理
- MySQL: Building the best INDEX for a given SELECT
- 《iOS 7 应用开发实战详解》
- jquery datepicker只显示年和月
热门文章
- Gym - 101375H MaratonIME gets candies 交互题
- page 页 分页 分段
- go install and go captcha
- [skill][git] git 常用操作记录
- Appium入门(6)__appium-desktop安装
- JQuery is()与hasClass()方法的对比
- Python接口自动化【requests处理Token请求】
- POJ2274 Long Long Message 字符串
- 洛谷P3242 接水果 [HNOI2015] 整体二分
- es的scoll滚动查询技术