题意:从有序链表中删除重复节点。

/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
if(head == NULL || head -> next == NULL){
return head;
}
if(head -> val == head -> next -> val){
return deleteDuplicates(head -> next);
}
else{
head -> next = deleteDuplicates(head -> next);
return head;
}
}
};

  

LeetCode 83. Remove Duplicates from Sorted List(从有序链表中删除重复节点)的更多相关文章

  1. [LeetCode] 83. Remove Duplicates from Sorted List ☆(从有序链表中删除重复项)

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

  2. [LeetCode] 26. Remove Duplicates from Sorted Array ☆(从有序数组中删除重复项)

    [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项 描述 Given a sorted array nums, remove the d ...

  3. [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项 II

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...

  4. [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项之二

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...

  5. [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二

    Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...

  6. 026 Remove Duplicates from Sorted Array 从排序数组中删除重复项

    给定一个有序数组,你需要原地删除其中的重复内容,使每个元素只出现一次,并返回新的长度.不要另外定义一个数组,您必须通过用 O(1) 额外内存原地修改输入的数组来做到这一点.示例:给定数组: nums ...

  7. LeetCode 82,考察你的基本功,在有序链表中删除重复元素II

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题的第51篇文章,我们来看LeetCode第82题,删除有序链表中的重复元素II(Remove Duplicates ...

  8. [LeetCode] 83. Remove Duplicates from Sorted List 移除有序链表中的重复项

    Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...

  9. [leetcode]83. Remove Duplicates from Sorted List有序链表去重

    Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...

随机推荐

  1. Vue - 如何使用npm run build后的dist文件夹

    脚手架vue cli生成项目后,使用 npm run build 生成了一个dist文件夹(应该是distribution的缩写) 只要放在http服务器上就可以运行. 使用一句python命令可以搭 ...

  2. (VLAN)理解Hybrid接口的应用

    实验三:理解Hybrid接口的应用 实验原理: 实验内容: 某企业二层网络使用两台S3700交换机S1和S2,且两台设备在不同的楼层.网络管理员规划了3个不同VLAN, HR部门使用VLAN 10,市 ...

  3. Java进阶学习(2)之对象交互(上)

    对象交互 对象交互 对象的识别 时钟小程序 把现实世界用对象去建模,去分解问题规模,最终抽象成对象和对象的模型 例如11:03的小程序,可以抽象成一个显示类,一个类生成两个对象去表示时钟 packag ...

  4. JAVA基础学习(3)之循环

    3循环 3.1循环 3.1.1循环 一直要做的行为进行循环 3.1.2数数字 while(){}判断是否进行 数数字:number/10 //数数字Scanner in = new Scanner(S ...

  5. mac机器smb映射

    1  finder中打开前往 2  输入:smb://10.216.90.*  链接 3  输入 账户和密码(名称和密码是你机器的smb密码:比如123***)

  6. workspace 打开的是我的电脑

    在system tree板块的空白处右键-->set root-->current workspace 即可恢复workspace.

  7. Spring 事务管理的使用

    Spring提供了2种事务管理 编程式的 声明式的(重点):包括xml方式.注解方式(推荐) 基于转账的demo dao层 新建包com.chy.dao,包下新建接口AccountDao.实现类Acc ...

  8. JavaSE复习~开发环境的搭建 与 HelloWorld

    JDK的下载 访问Oracle官网,下载jdk,目前来说用的最多的是 8 版本 https://www.oracle.com/technetwork/java/javase/downloads/ind ...

  9. java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time.....

    SpringBoot 2.1.4启动时报错 java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecogniz ...

  10. TCP网络调试助手上提示错误:“1035 未知错误”的有效解决方法,本人实测确实可行

    转:https://blog.csdn.net/jacket_/article/details/97415651 图片转载:https://blog.csdn.net/Alice_YCR/articl ...