当前位置:网站首页>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;
}
};
边栏推荐
- 如何使用MITMPROXy
- STC8H8K系列匯編和C51實戰——數碼管顯示ADC、按鍵串口回複按鍵號與ADC數值
- servlet的web.xml配置详解(3.0)
- CNN visualization technology -- detailed explanation of cam & grad cam and concise implementation of pytorch
- 穀歌出海創業加速器報名倒計時 3 天,創業人闖關指南提前收藏!
- Frequently asked questions about jetpack compose and material you
- Detailed steps of JS foreground parsing of complex JSON data "case: I"
- cookie插件和localForage离线储存插件
- Let every developer use machine learning technology
- Detailed notes of ES6
猜你喜欢
Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish
MySQL transaction and isolation level
Contest3147 - game 38 of 2021 Freshmen's personal training match_ 1: Maximum palindromes
Replace Django database with MySQL (attributeerror: 'STR' object has no attribute 'decode')
Google Go to sea entrepreneurship accelerator registration countdown 3 days, entrepreneurs pass through the guide in advance collection!
Contest3147 - game 38 of 2021 Freshmen's personal training match_ F: Polyhedral dice
Web components series (VIII) -- custom component style settings
ROS create workspace
Keepalived installation, use and quick start
神机百炼3.54-染色法判定二分图
随机推荐
Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish
Talking about MySQL database
Eco express micro engine system has supported one click deployment to cloud hosting
Deep learning classification network -- Network in network
从设计交付到开发,轻松畅快高效率!
Mock simulate the background return data with mockjs
Use some common functions of hbuilderx
Shenji Bailian 3.52-prim
Reading classic literature -- Suma++
LeetCode 27. 移除元素
ESP8266与STC8H8K单片机联动——天气时钟
Compte à rebours de 3 jours pour l'inscription à l'accélérateur de démarrage Google Sea, Guide de démarrage collecté à l'avance!
Web页面用户分步操作引导插件driver.js
Ros2 --- lifecycle node summary
Happy Lantern Festival | Qiming cloud invites you to guess lantern riddles
Contest3147 - game 38 of 2021 Freshmen's personal training match_ A: chicken
脑与认知神经科学Matlab Psytoolbox认知科学实验设计——实验设计四
VRRP之监视上行链路
经典文献阅读之--SuMa++
JWT tool class