当前位置:网站首页>LeetCode 83. 删除排序链表中的重复元素
LeetCode 83. 删除排序链表中的重复元素
2022-07-02 06:07:00 【大白羊_Aries】
题目描述
解法
一组快慢指针就搞定了
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
if (head == nullptr) return nullptr;
ListNode* slow = head;
ListNode* fast = head;
while (fast != nullptr)
{
if (fast->val != slow->val)
{
slow->next = fast;
slow = slow->next;
}
fast = fast->next;
}
slow->next = nullptr;
return head;
}
};
边栏推荐
- 从设计交付到开发,轻松畅快高效率!
- 经典文献阅读之--SuMa++
- token过期自动续费方案和实现
- Memcached installation
- 外部中断无法进入,删代码再还原就好......记录这个想不到的bug
- Detailed steps of JS foreground parsing of complex JSON data "case: I"
- Spark概述
- Unity Shader 学习笔记(3)URP渲染管线带阴影PBR-Shader模板(ASE优化版本)
- Google Play Academy 组队 PK 赛,正式开赛!
- Use some common functions of hbuilderx
猜你喜欢
Detailed notes of ES6
Shenji Bailian 3.54-dichotomy of dyeing judgment
Replace Django database with MySQL (attributeerror: 'STR' object has no attribute 'decode')
脑与认知神经科学Matlab Psytoolbox认知科学实验设计——实验设计四
网络相关知识(硬件工程师)
ZABBIX server trap command injection vulnerability (cve-2017-2824)
Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish
Shenji Bailian 3.53-kruskal
The official zero foundation introduction jetpack compose Chinese course is coming!
Linkage between esp8266 and stc8h8k single chip microcomputer - Weather Clock
随机推荐
Can't the dist packaged by vite be opened directly in the browser
【C语言】筛选法求素数
Common websites for Postgraduates in data mining
来自读者们的 I/O 观后感|有奖征集获奖名单
51 single chip microcomputer - ADC explanation (a/d conversion, d/a conversion)
Detailed notes of ES6
On Web server
Replace Django database with MySQL (attributeerror: 'STR' object has no attribute 'decode')
Format check JS
Google Go to sea entrepreneurship accelerator registration countdown 3 days, entrepreneurs pass through the guide in advance collection!
Picture clipping plug-in cropper js
Page printing plug-in print js
PHP parent
Flutter 混合开发: 开发一个简单的快速启动框架 | 开发者说·DTalk
Addchild() and addattribute() functions in PHP
JS determines whether the mobile terminal or the PC terminal
经典文献阅读之--SuMa++
From design delivery to development, easy and efficient!
Google play academy team PK competition, official start!
Frequently asked questions about jetpack compose and material you