当前位置:网站首页>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;
}
};
边栏推荐
- Stc8h8k Series Assembly and c51 Real combat - NIXIE TUBE displays ADC, Key Series port reply Key number and ADC value
- Addchild() and addattribute() functions in PHP
- 经典文献阅读之--SuMa++
- Web components series (VIII) -- custom component style settings
- Flutter hybrid development: develop a simple quick start framework | developers say · dtalk
- 让每一位开发者皆可使用机器学习技术
- STC8H8K系列汇编和C51实战——数码管显示ADC、按键串口回复按键号与ADC数值
- Servlet web XML configuration details (3.0)
- Redis Key-Value数据库 【秒杀】
- 如何使用MITMPROXy
猜你喜欢
随机推荐
On Web server
Happy Lantern Festival | Qiming cloud invites you to guess lantern riddles
Some experience of exercise and fitness
mock-用mockjs模拟后台返回数据
From design delivery to development, easy and efficient!
492. Construction rectangle
PHP array to XML
图片裁剪插件cropper.js
在uni-app中引入uView
ES6的详细注解
500. 键盘行
Little bear sect manual query and ADC in-depth study
CNN visualization technology -- detailed explanation of cam & grad cam and concise implementation of pytorch
Can't the dist packaged by vite be opened directly in the browser
Current situation analysis of Devops and noops
Mock simulate the background return data with mockjs
Brain and cognitive neuroscience matlab psychoolbox cognitive science experimental design - experimental design 4
[PHP是否安装了 SOAP 扩]对于php实现soap代理的一个常见问题:Class ‘SoapClient‘ not found in PHP的处理方法
使用HBuilderX的一些常用功能
Generics and generic constraints of typescript