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.

 /**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* deleteDuplicates(struct ListNode* head)
{
if(head==NULL)
return NULL; if(head!=NULL&&head->next==NULL)
return head; if(head->next->next==NULL)
{
if(head->val==head->next->val)
{
head->next==NULL;
return head->next;
} if(head->val!=head->next->val)
{
return head;
}
} struct ListNode* p;
p=head; int count=;
while(p!=NULL)
{
p=p->next;
count++;
} int *array;
array=(int *)malloc(count*sizeof(int)); p=head;
int i=;
while(p!=NULL)
{
array[i]=p->val;
i++;
p=p->next;
} p=head;
for(i=;i<count-;i++)
{
if(array[i]!=array[i+])
{
p->val= array[i];
p=p->next;
}
} p->val=array[count-];
p->next=NULL; return head;
}

LeeCode-Remove Duplicates from Sorted List的更多相关文章

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

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

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

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

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

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

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

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

  5. Leetcode-83 Remove Duplicates from Sorted List

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

  6. Remove Duplicates from Sorted List II

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

  7. Remove Duplicates From Sorted Array

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

  8. 【leetcode】Remove Duplicates from Sorted Array II

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

  9. 26. Remove Duplicates from Sorted Array

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

  10. 50. Remove Duplicates from Sorted Array && Remove Duplicates from Sorted Array II && Remove Element

    Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that e ...

随机推荐

  1. Hive 2、Hive 的安装配置(本地MySql模式)

    一.前提条件 安装了Zookeeper.Hadoop HDFS HA  安装方法: http://www.cnblogs.com/raphael5200/p/5154325.html 二.安装Mysq ...

  2. hdu 5335 Walk Out(bfs+寻找路径)

    Problem Description In an n∗m maze, the right-bottom corner or a written on it. An explorer gets los ...

  3. UGUI实现摇杆(模仿太极熊猫)

    核心代码: using UnityEngine; using System.Collections; using UnityEngine.UI; public delegate void Joysti ...

  4. handsontable的核心方法

    1.为handsontable添加钩子方法 addHook(key,callback):key为钩子方法名 <span style="font-size:18px;"> ...

  5. c# 委托delegate 编写计算器

    .Net 中的委托类似于 C 或 C++ 中的函数指针.使用委托使程序员可以将方法引用封装在委托对象内.然后可以将该委托对象传递给可调用所引用方法的代码,而不必在编译时知道将调用哪个方法.与 C 或 ...

  6. 关于js中select的简单操作,以及js前台计算,span简单操作

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  7. Hacker(十一)----黑客常用入侵方法

    Internet中,为了防止黑客入侵自己的电脑,就必须了解黑客入侵目标计算机的常用方法.黑客常用的入侵方法有数据驱动攻击.系统文件非法利用.伪造信息攻击.远端操纵等. 一.数据驱动攻击 数据驱动攻击是 ...

  8. 关于Http协议(2)--转载

    原文链接:http://www.cnblogs.com/mcad/ HTTP工作原理图 请求报文 1.请求报文长什么样?  Chrome核心的请求报文 2.报文结构 3.报文头部每个字段的意义 //从 ...

  9. Cookie同域,跨域单点登录(转)

    Cookie 同域单点登录 最近在做一个单点登录的系统整合项目,之前我们使用控件实现单点登录(以后可以介绍一下).但现在为了满足客户需求,在不使用控件情况下实现单点登录,先来介绍一下单点登录. 单点登 ...

  10. 前端--关于CSS

    CSS全名层叠样式表,层叠的含义有三个:1.按照特殊性的高低,特殊性高的覆盖特殊性低的样式声明:2.不同属性的样式声明要合并:3.后出现的相同的样式声明覆盖先出现的.所以要改变样式的优先级也有三种方法 ...