当前位置:网站首页>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;
}
};
边栏推荐
- Leverage Google cloud infrastructure and landing area to build enterprise level cloud native excellent operation capability
- Mathematical statistics and machine learning
- Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)
- 使用sha256文件验证下载的文件
- Current situation analysis of Devops and noops
- I/o multiplexing & event driven yyds dry inventory
- 500. 键盘行
- 【C语言】简单实现扫雷游戏
- Go 学习笔记整合
- mock-用mockjs模拟后台返回数据
猜你喜欢

数据回放伴侣Rviz+plotjuggler

Current situation analysis of Devops and noops
![[C language] simple implementation of mine sweeping game](/img/f7/15d561b3c329847971cabd4708c851.png)
[C language] simple implementation of mine sweeping game

Shenji Bailian 3.54-dichotomy of dyeing judgment

【C语言】简单实现扫雷游戏

Software testing Q & A

Web components series (VIII) -- custom component style settings

CNN可视化技术 -- CAM & Grad-CAM详解及pytorch简洁实现

经典文献阅读之--Deformable DETR

Little bear sect manual query and ADC in-depth study
随机推荐
Several keywords in C language
Deep learning classification network -- alexnet
cookie插件和localForage离线储存插件
492.构造矩形
Jetpack Compose 与 Material You 常见问题解答
Contest3147 - game 38 of 2021 Freshmen's personal training match_ E: Listen to songs and know music
51单片机——ADC讲解(A/D转换、D/A转换)
I/o multiplexing & event driven yyds dry inventory
Contest3147 - game 38 of 2021 Freshmen's personal training match_ G: Flower bed
PHP extensions
Redis Key-Value数据库 【秒杀】
社区说|Kotlin Flow 的原理与设计哲学
图片裁剪插件cropper.js
如何使用MITMPROXy
PHP inner class name is the same as the inner class method name
[C language] screening method for prime numbers
Little bear sect manual query and ADC in-depth study
STC8H8K系列汇编和C51实战——数码管显示ADC、按键串口回复按键号与ADC数值
官方零基础入门 Jetpack Compose 的中文课程来啦!
On Web server