当前位置:网站首页>LeetCode 83. Delete duplicate elements in the sorting linked list
LeetCode 83. Delete duplicate elements in the sorting linked list
2022-07-02 06:10:00 【Great white sheep_ Aries】
Title Description
83. Delete duplicate elements from the sort list
solution
A set of fast and slow pointers is done
/** * 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;
}
};
边栏推荐
猜你喜欢

Brain and cognitive neuroscience matlab psychoolbox cognitive science experimental design - experimental design 4

sudo提权

谷歌出海创业加速器报名倒计时 3 天,创业人闯关指南提前收藏!

深度学习分类网络--Network in Network

神机百炼3.52-Prim

CNN visualization technology -- detailed explanation of cam & grad cam and concise implementation of pytorch

I/o impressions from readers | prize collection winners list

Contest3147 - game 38 of 2021 Freshmen's personal training match_ F: Polyhedral dice

Happy Lantern Festival | Qiming cloud invites you to guess lantern riddles

经典文献阅读之--Deformable DETR
随机推荐
Problems encountered in uni app development (continuous update)
【C语言】筛选法求素数
Mock simulate the background return data with mockjs
Data playback partner rviz+plotjuggler
sudo提权
Mathematical statistics and machine learning
Redis key value database [primary]
Google play academy team PK competition, official start!
cookie插件和localForage离线储存插件
Redis Key-Value数据库 【高级】
外部中断无法进入,删代码再还原就好......记录这个想不到的bug
使用HBuilderX的一些常用功能
Sumo tutorial Hello World
ROS2----LifecycleNode生命周期节点总结
servlet的web.xml配置详解(3.0)
JWT tool class
External interrupts cannot be accessed. Just delete the code and restore it Record this unexpected bug
492. Construction rectangle
51 single chip microcomputer - ADC explanation (a/d conversion, d/a conversion)
脑与认知神经科学Matlab Psytoolbox认知科学实验设计——实验设计四