当前位置:网站首页>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;
}
};
边栏推荐
- Web页面用户分步操作引导插件driver.js
- sudo提权
- Contest3147 - game 38 of 2021 Freshmen's personal training match_ F: Polyhedral dice
- mock-用mockjs模拟后台返回数据
- Brain and cognitive neuroscience matlab psychoolbox cognitive science experimental design - experimental design 4
- 让每一位开发者皆可使用机器学习技术
- BGP中的状态机
- Ti millimeter wave radar learning (I)
- From design delivery to development, easy and efficient!
- ROS create workspace
猜你喜欢

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

memcached安装

Memcached installation

VRRP之监视上行链路

Contest3147 - game 38 of 2021 Freshmen's personal training match_ 1: Maximum palindromes

Deep learning classification network -- Network in network

Shenji Bailian 3.52-prim

Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish

How vite is compatible with lower version browsers

【C语言】简单实现扫雷游戏
随机推荐
ROS2----LifecycleNode生命周期节点总结
Jetpack Compose 与 Material You 常见问题解答
ROS create workspace
Deep learning classification network -- vggnet
Frequently asked questions about jetpack compose and material you
The real definition of open source software
Let every developer use machine learning technology
STC8H8K系列汇编和C51实战——按键允许按键计数(利用下降沿中断控制)
[C language] simple implementation of mine sweeping game
Leverage Google cloud infrastructure and landing area to build enterprise level cloud native excellent operation capability
Redis Key-Value数据库 【秒杀】
Reading classic literature -- Suma++
Some descriptions of Mipi protocol of LCD
Regular expression summary
JWT工具类
Happy Lantern Festival | Qiming cloud invites you to guess lantern riddles
Memcached installation
Linkage between esp8266 and stc8h8k single chip microcomputer - Weather Clock
Stc8h8k series assembly and C51 actual combat - serial port sending menu interface to select different functions
BGP 路由优选规则和通告原则