给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。

示例 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;
}
}

最新文章

  1. [WCF编程]12.事务:服务事务编程(下)
  2. Mac Pro 资源管理器 Double Commander“个性化设置” 备份
  3. React Native IOS源码初探
  4. Kotlin从入门到掉坑里
  5. 再说linux中的rm mv 遍历执行多个文件的操作: find + xagrs
  6. jsp_设置错误页
  7. ubuntu下matplotlib画图中文乱码问题
  8. 【转】 (C#)利用Aspose.Cells组件导入导出excel文件
  9. 关于Ionic的安装
  10. HDU 2102 A计划(DFS)
  11. android登录实现,存储数据到/data/data/包名/info.txt
  12. 8. Security-oriented operating systems (面向安全的操作系统 5个)
  13. Discuz!X 3.4 前台任意文件删除漏洞复现
  14. Python基础05_str_补充
  15. ads查询结果中文显示方框问题
  16. HTTP是什么?,GET与POST区别?
  17. 5月23日——SPA单页面应用的原理
  18. MySQL: Building the best INDEX for a given SELECT
  19. 《iOS 7 应用开发实战详解》
  20. jquery datepicker只显示年和月

热门文章

  1. Gym - 101375H MaratonIME gets candies 交互题
  2. page 页 分页 分段
  3. go install and go captcha
  4. [skill][git] git 常用操作记录
  5. Appium入门(6)__appium-desktop安装
  6. JQuery is()与hasClass()方法的对比
  7. Python接口自动化【requests处理Token请求】
  8. POJ2274 Long Long Message 字符串
  9. 洛谷P3242 接水果 [HNOI2015] 整体二分
  10. es的scoll滚动查询技术