Files
python/C++专题课程/到LeedCode刷题/leetcode基础篇/83.删除排序链表中的重复元素.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

56 lines
2.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*/*******************************************************************************
** **
** Jiedi(China nanjing)Ltd. **
** 创建:丁宋涛 夏曹俊,此代码可用作为学习参考 **
*******************************************************************************/
/*****************************FILE INFOMATION***********************************
**
** Project : 算法设计与编程实践---基于leetcode的企业真题库
** Contact : xiacaojun@qq.com
** 博客 : http://blog.csdn.net/jiedichina
** 视频课程 : 网易云课堂 http://study.163.com/u/xiacaojun
腾讯课堂 https://jiedi.ke.qq.com/
csdn学院 https://edu.csdn.net/course/detail/25037
** 51cto学院 http://edu.51cto.com/lecturer/index/user_id-100013755.html
** 老夏课堂 http://www.laoxiaketang.com
**
** 算法设计与编程实践---基于leetcode的企业真题库 课程群 :296249312 加入群下载代码和交流
** 微信公众号 : jiedi2007
** 头条号 : 夏曹俊
**
*****************************************************************************
//!!!!!!!!! 算法设计与编程实践---基于leetcode的企业真题库 课程 QQ群:296249312 下载代码和交流*/
/*
* @lc app=leetcode.cn id=83 lang=cpp
* 不断的去判断当前节点的下一个
* 元素的val是否与当前的val相同
* 相同的话,指向下一个节点的下一个节点
* [83] 删除排序链表中的重复元素
*/
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
ListNode* cur = head;
while(cur !=NULL){
ListNode* rear = cur->next;
if(rear == NULL)
return head;
if(cur->val == rear->val)
cur->next = rear->next;
else
cur = cur->next;
}
return head;
}
};