当前位置:网站首页>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;
}
};
边栏推荐
- memcached安装
- 495.提莫攻击
- Redis Key-Value数据库 【秒杀】
- Flutter hybrid development: develop a simple quick start framework | developers say · dtalk
- DRM display framework as I understand it
- Problems encountered in uni app development (continuous update)
- Error creating bean with name 'instanceoperatorclientimpl' defined in URL when Nacos starts
- Let every developer use machine learning technology
- Addchild() and addattribute() functions in PHP
- How vite is compatible with lower version browsers
猜你喜欢

Community theory | kotlin flow's principle and design philosophy

Spark overview

Shenji Bailian 3.52-prim

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

Compte à rebours de 3 jours pour l'inscription à l'accélérateur de démarrage Google Sea, Guide de démarrage collecté à l'avance!

51 single chip microcomputer - ADC explanation (a/d conversion, d/a conversion)

Detailed notes of ES6

Linkage between esp8266 and stc8h8k single chip microcomputer - Weather Clock

51单片机——ADC讲解(A/D转换、D/A转换)

The official zero foundation introduction jetpack compose Chinese course is coming!
随机推荐
Redis key value database [primary]
Error creating bean with name 'instanceoperatorclientimpl' defined in URL when Nacos starts
Brain and cognitive neuroscience matlab psychoolbox cognitive science experimental design - experimental design 4
cookie插件和localForage离线储存插件
servlet的web.xml配置详解(3.0)
memcached安装
Generics and generic constraints of typescript
ZABBIX server trap command injection vulnerability (cve-2017-2824)
ESP8266与STC8H8K单片机联动——天气时钟
Deep learning classification network -- Network in network
PHP obtains some values in the string according to the specified characters, and reorganizes the remaining strings into a new array
JWT tool class
深度学习分类网络--Network in Network
JWT工具类
来自读者们的 I/O 观后感|有奖征集获奖名单
Some descriptions of Mipi protocol of LCD
Compte à rebours de 3 jours pour l'inscription à l'accélérateur de démarrage Google Sea, Guide de démarrage collecté à l'avance!
Talking about MySQL database
Redis Key-Value数据库 【高级】
Deep learning classification network -- vggnet