题目:
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.

翻译:
给定一个排序号的链表,删除所有的重复元素,保证每个元素只出现一次。

分析:
在当前节点删除下一节点,会比较容易操作,只需要修改next指针。

代码:

/*** 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 null;}ListNode currentNode=head;while(currentNode.next!=null){if(currentNode.next.val==currentNode.val){currentNode.next=currentNode.next.next;}else{currentNode=currentNode.next;}}return head;}
}

Leet Code OJ 83. Remove Duplicates from Sorted List [Difficulty: Easy]相关推荐

  1. Leet Code OJ 26. Remove Duplicates from Sorted Array [Difficulty: Easy]

    题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...

  2. Leet Code OJ 4. Median of Two Sorted Arrays [Difficulty: Hard]

    题目 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...

  3. Leet Code OJ 102. Binary Tree Level Order Traversal [Difficulty: Easy]

    题目: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to ri ...

  4. Leet Code OJ 104. Maximum Depth of Binary Tree [Difficulty: Easy]

    题目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...

  5. [勇者闯LeetCode] 83. Remove Duplicates from Sorted List

    [勇者闯LeetCode] 83. Remove Duplicates from Sorted List Description Given a sorted linked list, delete ...

  6. 26. Remove Duplicates from Sorted Array【easy】

    26. Remove Duplicates from Sorted Array[easy] Given a sorted array, remove the duplicates in place s ...

  7. [leetcode]83.Remove Duplicates from Sorted List

    题目 Given a sorted linked list, delete all duplicates such that each element appear only once. Exampl ...

  8. leetcode python3 简单题83. Remove Duplicates from Sorted List

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第八十三题 (1)题目 英文: Given a sorted linked list ...

  9. 【LeetCode OJ】Remove Duplicates from Sorted List

    2019独角兽企业重金招聘Python工程师标准>>> Given a sorted linked list, delete all duplicates such that eac ...

最新文章

  1. 学 Python 必看书单汇总
  2. 发布 | 《工业安全大数据蓝皮书》(2021年)
  3. Codeforces 859C - Pie Rules
  4. 简单android音乐播放器课程设计,android音乐播放器课程设计报告.doc
  5. 使用ilmerge实现.net程序静态链接
  6. LiveVideoStack主编观察04 /
  7. 如何判断当前请求的API类型
  8. window下批处理:打开命令窗口且执行后不关闭
  9. c语言一个整数各位数字个数_C语言编写程序输出10个整数中最小值或最大值
  10. 【分布式】Zookeeper的服务器角色
  11. csv 读写 python_Python CSV读写
  12. Http get与pos
  13. 超链接小点html,html超链接取消鼠标点指显示小手
  14. imdisk虚拟光驱安装linux,ImDisk Virtual Disk Driver(虚拟光驱)
  15. 关于源级串联电感提高稳定性的理由
  16. 如何快速在手机上修改证件照底色
  17. 模板类继承后找不到父类函数的问题
  18. 校园招聘-2017携程秋招后台开发笔试编程题
  19. 笔记本计算机屏幕亮度暗,笔记本屏幕100%还是暗,win10电脑亮度调节失灵
  20. vector erase

热门文章

  1. 大华监控服务器显示感叹号灯亮,仪表盘出现黄色感叹号灯亮什么问题
  2. OpenCV_008-OpenCV 中的图像算术运算
  3. C语言程序设计 | 模拟实现内存操作函数:strncpy, strncat, strncmp, memcpy, memmove
  4. Python 让所有奇数都在偶数前面,而且奇数升序排列,偶数降序排序
  5. 提升你的代码——Lambda!
  6. 又一本 Go 语言力作出版了
  7. Linux中的基础IO(二)
  8. dav1d 0.5.1:更快!
  9. 张军:围绕“WebRTC+AI+大数据”创新
  10. Java多线程之volatile详解