就是将链表中的重复元素去除

我的方法很简单就是如果链表的前后元素相同的话,将后一个元素删除

 /**
* 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* now = head;
while(now && now->next){
ListNode* next = now->next;
if(now->val == next->val){
now->next = next->next;
delete next;
}
else{
now = now->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. Example 1 ...

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

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

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

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

  4. LeetCode 83. Remove Duplicates from Sorted List (从有序链表中去除重复项)

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

  5. [LeetCode]83. Remove Duplicates from Sorted List(排序链表去重)

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

  6. leetCode 83.Remove Duplicates from Sorted List(删除排序链表的反复) 解题思路和方法

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

  7. LeetCode 83. Remove Duplicates from Sorted List(从有序链表中删除重复节点)

    题意:从有序链表中删除重复节点. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode ...

  8. Java [Leetcode 83]Remove Duplicates from Sorted List

    题目描述: Given a sorted linked list, delete all duplicates such that each element appear only once. For ...

  9. [LeetCode] 83. Remove Duplicates from Sorted List_Easy tag: Linked List

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

随机推荐

  1. ASP.NET ZERO 学习 JTable的ChildTable用法

    效果图: Jtable的子表用法: _$masterTable.jtable({ title: app.localize('PharmacyInventory'), openChildAsAccord ...

  2. [转]Linux vi 编辑后如何保存

    比如:vi /etc/vsftpd/vsftpd.conf 按ESC键 跳到命令模式,然后: :w 保存文件但不退出vi :w file 将修改另外保存到file中,不退出vi :w! 强制保存,不推 ...

  3. C++队列中应该注意的一些问题

    第一次在C++中写类,新手,见笑 #include<iostream.h>#include<iostream>template<typename T> class ...

  4. centos搭建NFS网络文件系统

    NFS服务器端 安装NFS服务器非常之简单: yum install nfs-utils protmap 这样就安装好了,其中nfs-utils是提供NFS服务器程序和相应的管理工具.protmap是 ...

  5. UILabel的常用属性

    UILabel常用属性1——实例化和设置文字 // 实例化UILabel并指定其边框 UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake ...

  6. Linux命令(1)- grep

    1.grep 功能:查找文件里符合条件的字符串. 语法:grep [-abcEFGhHilLnqrsvVwxy][-A<显示列数>][-B<显示列数>][-C<显示列数& ...

  7. andorid SQLite数据库的增删改查 和事务操作

    .xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...

  8. 使用并行的方法计算斐波那契数列 (Fibonacci)

    更新:我的同事Terry告诉我有一种矩阵运算的方式计算斐波那契数列,更适于并行.他还提供了利用TBB的parallel_reduce模板计算斐波那契数列的代码(在TBB示例代码的基础上修改得来,比原始 ...

  9. android里R.layout.的问题

    今天,在Exlipse里的一个项目在.java文件里写  setContentView(R.layout.activity_problem);时,显示错误,以为是R.java文件里没有对应的activ ...

  10. 团队作业week2

    软件分析和用户需求调查 (2013) 具体内容参看邹欣老师的博客:http://www.cnblogs.com/xinz/p/3308608.html. 作业提交期限:2013年9月25日上课前.