原题 Remove Duplicates from Sorted List

有序单链表去重,delete 只能对指针起作用。

/**
* 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) return NULL; ListNode *pp = head;
ListNode *p = head->next; while (p != NULL)
{
if (p->val == pp->val)
{
pp->next = p->next;
delete p;
p = pp->next;
continue;
}
pp = p;
p = p->next;
};
return head;
}
};

3月3日(4) Remove Duplicates from Sorted List的更多相关文章

  1. 【LeetCode】82. Remove Duplicates from Sorted List II 解题报告(Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/remove-du ...

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

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

  3. [LeetCode] Remove Duplicates from Sorted List II 移除有序链表中的重复项之二

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

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

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

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

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

  6. Leetcode-83 Remove Duplicates from Sorted List

    #83. Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such that ...

  7. Remove Duplicates from Sorted List II

    Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...

  8. Remove Duplicates From Sorted Array

    Remove Duplicates from Sorted Array LeetCode OJ Given a sorted array, remove the duplicates in place ...

  9. 【leetcode】Remove Duplicates from Sorted Array II

    Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...

随机推荐

  1. Java_基础_内存管理

    把没几多年,完全忘记了把自己学的东西记录下来了,现在也基本不知道怎么去记录会更好了,不过好歹妹是把住了~也要毕业了,继续回来写东东记录自己的学习...... 一个Java程序在运行时的内存分布主要如上 ...

  2. jackson使用示例

    Jackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json.xml转换成Java对象. Jackson 2.x版提供了三个JAR包供下载: 1. Core库:strea ...

  3. Docker 底层实现

    基本架构 Docker 采用了 C/S架构,包括客户端和服务端. Docker daemon 作为服务端接受来自客户的请求,并处理这些请求(创建.运行.分发容器). 客户端和服务端既可以运行在一个机器 ...

  4. what is docker

    尽管之前久闻Docker的大名了,但是天资愚钝,对其到底是个啥东西一直摸不清,最近花了一段时间整理了一下,算是整理出一点头绪来. 官网的介绍是这样的: Docker is an open platfo ...

  5. C# 之 集合整理

    集合,表示可以通过遍历每个元素来访问的一组对象(特别是可使用foreach循环访问):一个集合包括多个元素,即有一个集合类对象和N个元素对象. BCL(Base Class Library, 基类库) ...

  6. EntityFramework优缺点(转)

    Entity Framework  是微软推荐出.NET平台ORM开发组件, 现在已放源代码.  以下我们来讨论一下优缺点和一些问题, 以下简称EF.  有兴趣可查询官网的Entity Framewo ...

  7. encodeURIComponent() 和 encodeURI()

    encodeURI(URIstring): 该方法不会对 ASCII 字母和数字进行编码,也不会对这些 ASCII 标点符号进行编码: - _ . ! ~ * ' ( ) . 该方法的目的是对 URI ...

  8. Timed Code

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...

  9. Git 暂存区

    可以用 git log 查看提交日志(附加的 --stat 参数可以看到每次提交的文件变更统计). $ cd /path/to/my/workspace/demo $ git log --stat 如 ...

  10. JdbcTemplate 、NamedParameterJdbcTemplate、SimpleJdbcTemplate的区别

    一.JdbcTemplate 首先在配置文件中设置数据源 <bean id="dataSource" class="org.springframework.jdbc ...