[leetcode-83-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.
思路:
用两个指针,一个在前,一个在后,比较两个结点的值,如果相等,后一个指针后移,再比较。
如果不相等,则前一个指针指向后一个指针,然后同时后移。
ListNode* deleteDuplicates(ListNode* head){if (head == NULL || head->next == NULL) return head; ListNode* p = head, *q = head->next;while (q != NULL){if (p->val == q->val){}else{p->next = q;p = q;}q = q->next;}p->next = q;return head;}
转载于:https://www.cnblogs.com/hellowooorld/p/6679588.html
[leetcode-83-Remove Duplicates from Sorted List]相关推荐
- [勇者闯LeetCode] 83. Remove Duplicates from Sorted List
[勇者闯LeetCode] 83. Remove Duplicates from Sorted List Description Given a sorted linked list, delete ...
- [leetcode]83.Remove Duplicates from Sorted List
题目 Given a sorted linked list, delete all duplicates such that each element appear only once. Exampl ...
- LeetCode 83. Remove Duplicates from Sorted List
题目: Given a sorted linked list, delete all duplicates such that each element appear only once. For e ...
- LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] c++
LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++> 给出排序好的 ...
- Leetcode OJ: Remove Duplicates from Sorted Array I/II
删除排序数组重复元素,先来个简单的. Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates i ...
- LeetCode 80. Remove Duplicates from Sorted Array II
80. Remove Duplicates from Sorted Array II My Submissions QuestionEditorial Solution Total Accepted: ...
- LeetCode之Remove Duplicates from Sorted Array II
1.题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ...
- leetcode python3 简单题83. Remove Duplicates from Sorted List
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第八十三题 (1)题目 英文: Given a sorted linked list ...
- 【leetcode】Remove Duplicates from Sorted Array
题目:Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- LeetCode之Remove Duplicates from Sorted Array
1.题目 Given a sorted array, remove the duplicates in place such that each element appear only once an ...
最新文章
- php 开启mysql_php如何开启mysqli扩展
- python二维游戏编程 超级大脑_超级大脑教练 - 主页
- 内核代号101 — 动手写自己的内核
- H5 Canvas刮刮乐
- 【渝粤题库】陕西师范大学202321投资银行学 作业(专升本)
- 修改linux绑定的域名,手工修改linux系统下DA面板绑定的域名
- elasticsearch date_MySQL数据实时增量同步到Elasticsearch
- linux 服务器(CentOS7)搭建PHP环境+SSH配置+服务器文件上传配置
- mysql 实例与用户_MySQL(17):用户登录实例
- python基础0304
- xxl-job使用笔记
- Educoder Matplotlib和Seaborn三维图 第2关:曲面三角剖分
- Symmetric Tree
- append追加的html中富文本失效,jquery append 动态添加的元素事件on 不起作用的解决方案...
- 最好用的PDF软件汇总
- 高中数学竞赛书籍推荐
- 数学建模(NO.9斯皮尔曼相关系数)
- python语言月份缩写_[宜配屋]听图阁
- visual studio code打开预览.md文件
- Android P SELinux (二) 开机初始化与策略文件编译过程
热门文章
- 如何发布第一个属于自己的npm包
- sublime快捷键设置
- 数字三角形_递归_递推(动态规划)
- 修改Chrome默认搜索引擎为Google.com
- OVS-vsctl的帮助文件的中文版
- 基础才是重中之重~如何整理BLL与DAL层的文件
- (整理)C/C++野指针
- DWR学习笔记 - Hello World
- Sql server在另一台服务器,在Visual Studio 中没问题,IIS中 提示“在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。。。。”...
- linux中的设备名称和设备号