当前位置:网站首页>LeetCode 83、删除排序链表中的重复元素
LeetCode 83、删除排序链表中的重复元素
2022-04-22 12:17:00 【亡于灬】
83、删除排序链表中的重复元素
1)题目描述
给定一个已排序的链表的头 head , 删除所有重复的元素,使每个元素只出现一次 。返回 已排序的链表 。
示例 1:

输入:head = [1,1,2]
输出:[1,2]
示例 2:

输入:head = [1,1,2,3,3]
输出:[1,2,3]
提示:
- 链表中节点数目在范围
[0, 300]内 -100 <= Node.val <= 100- 题目数据保证链表已经按升序 排列
2)分析
一次遍历。遍历过程中,如果当前结点的值和下一个结点的值相等,删除下一个结点,否则移动到下一个结点。
3)C++代码
/** * 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)
return head;
ListNode* curr=head;
while(curr->next){
if(curr->val==curr->next->val)
curr->next=curr->next->next;
else
curr=curr->next;
}
return head;
}
};
版权声明
本文为[亡于灬]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_38342510/article/details/124337883
边栏推荐
- MySQL学习第四弹——多表查询分类以及案例练习源码详解
- Case 4-1.4: path in the reactor (simulation establishment and simulation path of small top reactor)
- 2019年华为鸿蒙加入手机系统阵营,如何看待鸿蒙这三年的发展?
- 模糊集合论
- JS [detailed] scope
- Electrician Lecture 2
- Research shows that young people are more and more reluctant to change their mobile phones. What are the hardware updates of the next generation of smart phones that will make you have the impulse to
- ESP32-CAM使用历
- congratulations! You have been concerned about the official account for 1 years, and invite you to join NetEase data analysis training.
- 【生活中的逻辑谬误】以暴制暴和压制理性
猜你喜欢

MySQL之父:代码应该一次写成,而不是后面再改

Software intelligence: the AI service function of AAAS system: the relationship between the unconscious agent function of outline map and gossip map
![【深入理解TcaplusDB技术】读取列表指定位置数据接口说明——[List表]](/img/ed/cccd5dee09d2f0a3e6c788bd265b36.png)
【深入理解TcaplusDB技术】读取列表指定位置数据接口说明——[List表]

UML summary

Comparison of data protection modes between Oracle data guard and Jincang kingbasees cluster

congratulations! You have been concerned about the official account for 1 years, and invite you to join NetEase data analysis training.

电工第一讲

刷了一千道选择题,我总结了这些C语言易错点【第二弹】

Where have all the Internet people who left their jobs gone?

可以测量50A以上电流的隔离集成式电流传感器CH704应用案例分享
随机推荐
base64加密解密和json处理
Huawei Hongmeng joined the mobile phone system camp in 2019. How do you view the development of Hongmeng in the past three years?
Father of MySQL: the code should be written at once, not later
"Open source summer" activity is hot. In the registration, rich bonuses are waiting for you to get!
Base64 encryption, decryption and JSON processing
机器学习 训练模板,汇总多个分类器
Distributed transaction and lock
STM32F429BIT6 SD卡模拟U盘
Quantitative system development and quantitative trading system app construction
有研究显示,现在年轻人越来越不愿意换手机了。下一代智能手机在硬件上出现哪些更新,才会让你有换机的冲动?
Take you to Huawei cloud Conference [play with Huawei cloud]
Some problems in the use of zuul
1086 Tree Traversals Again (25 分)
[Tang Laoshi] subcontracting and sticking in unity network communication
订货系统打破批发企业瓶颈期,助力企业数字化转型
Interpretation of tamigou project | 49.5% equity transfer of Beijing Hualong pawn Co., Ltd
Developer friendly public chain Neo | how to connect web2 developers to Web3 world
Redis新版本发布,你还认为Redis是单线程?
[deeply understand tcallusdb technology] delete all data interface descriptions in the list - [list table]
Source code analysis of ViewModel