当前位置:网站首页>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;
}
};
边栏推荐
- 经典文献阅读之--SuMa++
- Contest3147 - game 38 of 2021 Freshmen's personal training match_ 1: Maximum palindromes
- AttributeError: ‘str‘ object has no attribute ‘decode‘
- How to use mitmproxy
- Cookie plugin and localforce offline storage plugin
- Summary of MySQL constraints
- Nacos 启动报错 Error creating bean with name ‘instanceOperatorClientImpl‘ defined in URL
- JS determines whether the mobile terminal or the PC terminal
- Detailed steps of JS foreground parsing of complex JSON data "case: I"
- 亚马逊aws数据湖工作之坑1
猜你喜欢
Contest3147 - game 38 of 2021 Freshmen's personal training match_ A: chicken
来自读者们的 I/O 观后感|有奖征集获奖名单
Detailed notes of ES6
Eco express micro engine system has supported one click deployment to cloud hosting
LeetCode 78. 子集
Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)
线性dp(拆分篇)
Regular expression summary
亚马逊aws数据湖工作之坑1
BGP报文详细解释
随机推荐
神机百炼3.52-Prim
LeetCode 39. 组合总和
谷歌出海创业加速器报名倒计时 3 天,创业人闯关指南提前收藏!
Lambda 表达式 和 方法引用
LeetCode 47. 全排列 II
LeetCode 283. 移动零
Comment utiliser mitmproxy
Jetpack Compose 与 Material You 常见问题解答
浏览器原理思维导图
[C language] simple implementation of mine sweeping game
Unity Shader 学习笔记(3)URP渲染管线带阴影PBR-Shader模板(ASE优化版本)
From design delivery to development, easy and efficient!
Reading classic literature -- Suma++
Frequently asked questions about jetpack compose and material you
servlet的web.xml配置详解(3.0)
Style modification of Mui bottom navigation
步骤详解 | 助您轻松提交 Google Play 数据安全表单
memcached安装
How vite is compatible with lower version browsers
从设计交付到开发,轻松畅快高效率!