当前位置:网站首页>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;
}
};
边栏推荐
- Google Go to sea entrepreneurship accelerator registration countdown 3 days, entrepreneurs pass through the guide in advance collection!
- 神机百炼3.52-Prim
- TI毫米波雷达学习(一)
- Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish
- 深度学习分类网络--Network in Network
- 脑与认知神经科学Matlab Psytoolbox认知科学实验设计——实验设计四
- ROS2----LifecycleNode生命周期节点总结
- PHP parent
- Data playback partner rviz+plotjuggler
- 网络相关知识(硬件工程师)
猜你喜欢

keepalived安装使用与快速入门

Google play academy team PK competition, official start!

深度学习分类网络--VGGNet

Software testing Q & A

I/o impressions from readers | prize collection winners list

如何使用MITMPROXy

Flutter 混合开发: 开发一个简单的快速启动框架 | 开发者说·DTalk

How vite is compatible with lower version browsers

DRM display framework as I understand it

Google Play Academy 组队 PK 赛,正式开赛!
随机推荐
在uni-app中引入uView
Web components series (VIII) -- custom component style settings
Ros2 --- lifecycle node summary
Redis key value database [primary]
500. 键盘行
Several keywords in C language
神机百炼3.53-Kruskal
PHP array to XML
穀歌出海創業加速器報名倒計時 3 天,創業人闖關指南提前收藏!
PHP read file (read JSON file, convert to array)
Generics and generic constraints of typescript
Shenji Bailian 3.54-dichotomy of dyeing judgment
复杂 json数据 js前台解析 详细步骤《案例:一》
经典文献阅读之--Deformable DETR
TI毫米波雷达学习(一)
Problems encountered in uni app development (continuous update)
谷歌出海创业加速器报名倒计时 3 天,创业人闯关指南提前收藏!
【C语言】筛选法求素数
Brain and cognitive neuroscience matlab psychoolbox cognitive science experimental design - experimental design 4
【C语言】简单实现扫雷游戏