[leetcode.com]算法题目 - Remove Duplicates from Sorted List
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;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *deleteDuplicates(ListNode *head) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
ListNode *p;
p = head;
if(!p) return head; while(p->next){
if(p->next->val == p->val){
ListNode *q;
q=p->next;
p->next = q->next;
delete q;
}
else{
p = p->next; }
} return head;
}
};
思路:考察链表的基本操作,只要注意细节就没问题。
[leetcode.com]算法题目 - Remove Duplicates from Sorted List的更多相关文章
- [算法题] Remove Duplicates from Sorted Array ii
题目内容 本题来源LeetCode Follow up for "Remove Duplicates": What if duplicates are allowed at mos ...
- LeetCode之“链表”:Remove Duplicates from Sorted List && Remove Duplicates from Sorted List II
1. Remove Duplicates from Sorted List 题目链接 题目要求: Given a sorted linked list, delete all duplicates s ...
- <LeetCode OJ> 83. Remove Duplicates from Sorted List
83. Remove Duplicates from Sorted List Total Accepted: 94387 Total Submissions: 264227 Difficulty: E ...
- leetCode练题——26. Remove Duplicates from Sorted Array
1.题目 26. Remove Duplicates from Sorted Array--Easy Given a sorted array nums, remove the duplicates ...
- LeetCode(28)-Remove Duplicates from Sorted Array
题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- LeetCode(80)Remove Duplicates from Sorted Array II
题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...
- LeetCode算法题-Remove Duplicates from Sorted List
这是悦乐书的第160次更新,第162篇原创 01 前情回顾 昨晚的爬楼梯算法题,有位朋友提了个思路,使用动态规划算法.介于篇幅问题,这里不细说动态规划算法,以后会在数据机构和算法的理论知识里细说. 昨 ...
- 【算法】LeetCode算法题-Remove Duplicates from Sorted Array
这是悦乐书的第149次更新,第151篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第8题(顺位题号是26).给定一个已经排序(由小到大)的整数数组(元素可以重复),计算其 ...
- [算法题] Remove Duplicates from Sorted Array
题目内容 本题来源于LeetCode Given a sorted array, remove the duplicates in place such that each element appea ...
随机推荐
- java mail 读取邮件列表,
// 准备连接服务器的会话信息 Properties props = new Properties(); props.setProperty("mail.store.protocol&quo ...
- PHP + Redis 队列实战
环境 centos6.5 PHP5.3 Redis安装 #yum install redis 1.redis配置认证密码 #vi /etc/redis.conf requirepass mypass ...
- Tomcat新问题 还没有解决:the apr based apache tomcat native librariy which allows optional perf...........
问题信息详细: 2012-5-18 18:41:54 org.apache.catalina.core.AprLifecycleListener init 信息: The APR based Apa ...
- Peter的烟(水题测试2017082401&洛谷1150)
题目链接:Peter的烟 这道题基本做法很水,不解释. #include<bits/stdc++.h> using namespace std; int main(){ int n,k; ...
- 初识python函数
一.函数 1.什么是函数 函数是对功能或者动作的封装 2.函数的语法和定义 def 函数名(): 函数体 调用: 函数名() 3.关于函数的返回值 return : 返回 1.当程序没写过retur ...
- mysql字符串类型数据
字符串类型是在数据库中存储字符串的数据类型,字符串类型包括char,varchar,text,enum和set. OK,我们来一个一个的看下上面提到的几种类型. char类型和varchar类型 ch ...
- 2018.11.01 NOIP训练 树的排列(树形dp)
传送门 跟这道题差不多. 只不过是让权值小的儿子做权值大的儿子的父亲而已. 代码
- PHP中奖概率实现
$prize_arr = array( '0' => array('id'=>1,'prize'=>'elm_1','rate'=>1), '1' => array('i ...
- R入门(一)
简单的算术操作和向量运算 向量赋值:函数c( ),参数可以是一个或多个数,也可以是向量 赋值符号‘<-’ 向量运算:exp(),log(),sin(),tan(),sqrt(),max(),mi ...
- python模块:pickle
"""Create portable serialized representations of Python objects. See module copyreg f ...