当前位置:网站首页>83. 删除排序链表中的重复元素
83. 删除排序链表中的重复元素
2022-06-11 08:55:00 【拽拽就是我】
leetcode力扣刷题打卡
题目:83. 删除排序链表中的重复元素
描述:给定一个已排序的链表的头 head , 删除所有重复的元素,使每个元素只出现一次 。返回 已排序的链表 。
解题思路
1、注意head可能为空节点;
2、如果当前节点和next节点相同,就一直往后next,一直到不同为止;
原代码##
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
if (!head) return nullptr;
ListNode *p = head;
while (head->next) {
if (head->val == head->next->val) head->next = head->next->next;
else head = head->next;
}
return p;
}
};
边栏推荐
- 2022 Niuke winter vacation 3
- Matlab learning 9- nonlinear sharpening filter for image processing
- M1 chip guide: M1, M1 pro, M1 Max and M1 ultra
- SAP ABAP field symbol
- 预编译,编译,汇编,链接,静态库,动态库都是什么
- Usage and difference between map and set in JS
- EN 45545-2t10 precautions for smoke density detection by Horizontal method
- Getting started with Zipkin
- SAP 物料主数据归档
- Hibernate L2 cache
猜你喜欢

MySQL核心点笔记

leetcode - 230. The k-th smallest element in a binary search tree

leetcode - 518. Change II

What is concurrent search set? Are you still worried about it? In fact, it is a problem of connected graph, which is not so difficult to understand

Can not connect to local MySQL server through socket ‘/tmp/mysql. sock (2)‘

Sword finger offer 51 Reverse pair in array

【clickhouse专栏】新建库角色用户初始化

Introduction to knowledge atlas -- yedda annotation

【C语言-数据存储】数据在内存中是怎样存储的?

【Image Processing】空间域图像增强
随机推荐
File system check of the root filesystem failed
Textview text size auto fit and textview margin removal
Standardized compilation knowledge
How to apply for BS 476-7 sample for display? Is it the same as the display
Matlab学习9-图像处理之非线性锐化滤波
M1 芯片指南:M1、M1 Pro、M1 Max 和 M1 Ultra
Analysis of EN 45545 R24 oxygen index test method
光伏板怎么申请ASTM E108阻燃测试?
2、 Rendering camera data
Mazhiqiang: research progress and application of speech recognition technology -- RTC dev Meetup
LiveData 与 StateFlow,我该用哪个?
Notes on MySQL core points
【C语言-数据存储】数据在内存中是怎样存储的?
2022 Niuke winter vacation 3
CMVSS TSD No. 302与49 CFR 571.302测试方法是否一样
Sword finger offer 21 Adjust array order so that odd numbers precede even numbers
指定环境下安装Jupyter
Codeworks round 723 (Div. 2)
Supplementary provision plan codeworks round 760 (Div. 3)
GCC AVR (ATMEL studio+ AVR studio) how to define the structure array in the program memory (flash) space and read it