一、     题目

给定一个排好序的链表,删除全部反复的节点,使每个节点都仅仅出现一次

比如:

Given 1->1->2, return 1->2.

Given 1->1->2->3->3, return1->2->3.

二、     分析

刚看到题目时。没有看到sorted这个关键词。还以为要使用数组或空间保存经过的节点,然后每次再保存…….还是对英文不感冒啊!所以那就非常easy了,直接遍历,假设反复了那就直接删除OK,否则直接后移到下一个节点。

比較的时候要注意空节点就OK了!

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

Leetcode:remove_duplicates_from_sorted_list的更多相关文章

  1. 我为什么要写LeetCode的博客?

    # 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...

  2. LeetCode All in One 题目讲解汇总(持续更新中...)

    终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...

  3. [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  4. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  5. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  6. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

  7. Leetcode 笔记 100 - Same Tree

    题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...

  8. Leetcode 笔记 99 - Recover Binary Search Tree

    题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...

  9. Leetcode 笔记 98 - Validate Binary Search Tree

    题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...

随机推荐

  1. hdu 2462(欧拉定理+高精度快速幂模)

    The Luckiest number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  2. jquery小技巧:使用jquery.confirm和PNotify实现弹出提示和消息提示

    在从UIKIT前端换到BOOSTRAP前端时,一些转换的技巧. https://myclabs.github.io/jquery.confirm/ http://sciactive.github.io ...

  3. [Machine Learning with Python] Familiar with Your Data

    Here I list some useful functions in Python to get familiar with your data. As an example, we load a ...

  4. 矩阵乘法加速fib数列

    考虑矩阵(1,1)(1,0) #include<cstdio> #include<cstring> #include<iostream> using namespa ...

  5. luogu P3402 最长公共子序列

    题目背景 DJL为了避免成为一只咸鱼,来找Johann学习怎么求最长公共子序列. 题目描述 经过长时间的摸索和练习,DJL终于学会了怎么求LCS.Johann感觉DJL孺子可教,就给他布置了一个课后作 ...

  6. 某考试 T3 Try to find out the wrong in the test

    Discription Hint: 对于 100% 的数据, n<=10^6.

  7. Android NDK 环境配置

    1. 下载NDK 官方链接地址: http://developer.android.com/tools/sdk/ndk/index.html 下载下来的应该是这个东西(以后可能会有更新,但步骤变动不会 ...

  8. 【GitHub】给GitHub上的ReadMe.md文件中添加图片怎么做 、 gitHub创建文件夹

    1.首先在github上的仓库上,创建一个空的文件夹,用于上传图片 上图看 要点击的按钮是创建新的文件,并不是创建新的文件夹,具体怎么?往下看 这个时候,下面的提交按钮才能提交 2.进入新创建的文件夹 ...

  9. [反汇编练习] 160个CrackMe之031

    [反汇编练习] 160个CrackMe之031. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...

  10. C 标准库 - <stddef.h>

    C 标准库 - <stddef.h> 简介 stddef .h 头文件定义了各种变量类型和宏.这些定义中的大部分也出现在其它头文件中. 库变量 下面是头文件 stddef.h 中定义的变量 ...