当前位置:网站首页>【OR36 链表的回文结构】
【OR36 链表的回文结构】
2022-06-22 19:41:00 【爱吃榴莲的喵星人】
一、题目描述
二、提供方便走读代码的图

三、题目代码
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) {} };*/
struct ListNode *findMid(struct ListNode*head)
{
struct ListNode* fast=head;
struct ListNode* slow=head;
while(fast&&fast->next)
{
slow=slow->next;
fast=fast->next->next;
}
return slow;
}
struct ListNode * reserve(struct ListNode*head)
{
struct ListNode*newHead=NULL;
struct ListNode*cur=head;
while(cur)
{
struct ListNode*next=cur->next;
cur->next=newHead;
newHead=cur;
cur=next;
}
return newHead;
}
class PalindromeList {
public:
bool chkPalindrome(ListNode* A) {
ListNode* mid=findMid(A);
ListNode*head=reserve(mid);
ListNode*rhead=head;
ListNode*Ahead=A;
while(rhead&&Ahead)
{
if(rhead->val!=Ahead->val)
{
return false;
}
else
{
rhead=rhead->next;
Ahead=Ahead->next;
}
}
return true;
}
};
以上是本篇文章的全部内容,如果文章有错误或者有看不懂的地方,多和喵博主交流。互相学习互相进步。如果这篇文章对你有帮助,可以给喵博主一个关注,你们的支持是我最大的动力。
边栏推荐
- Raspberry pie environment settings
- Oh, my God, it's a counter attack by eight part essay
- [resolved] -go_ out: protoc-gen-go: Plugin failed with status code 1.
- R语言AirPassengers数据集可视化
- Code to image converter
- 扩展Ribbon支持基于元数据的版本管理
- 超快变形金刚 | 用Res2Net思想和动态kernel-size再设计 ViT,超越MobileViT
- 深度学习常用损失函数总览:基本形式、原理、特点
- 百家讲坛 雍正十三年(下部)
- Agricultural futures account opening
猜你喜欢

2022团体程序设计天梯赛L1

Visualization of wine datasets in R language
![[observation] innovation in the software industry has entered a](/img/b8/232ce6bc41a4154f6c9d48b0819d8f.png)
[observation] innovation in the software industry has entered a "new cycle". How can we make a new start in the changing situation?

NumPy学习笔记(六)——sum()函数

AAAI 2022 | 传统GAN修改后可解释,并保证卷积核可解释性和生成图像真实性

慕课6、实现负载均衡-Ribbon

R语言 co2数据集 可视化

讲真,Kotlin 协程的挂起没那么神秘(原理篇)
Solutions to Oracle system/ user locking

Resolved: can there be multiple auto incrementing columns in a table
随机推荐
R 语言USArrests 数据集可视化
Stochastic Adaptive Dynamics of a Simple Market as a Non-Stationary Multi-Armed Bandit Problem
性能测试(一)
Introduction to JWT
已解决:一个表中可以有多个自增列吗
SwiftUI如何模拟视图发光增大的动画效果
MySQL foundation - constraints
真正的缓存之王Caffine Cache
uniapp小程序商城开发thinkphp6积分商城、团购、秒杀 封装APP
89-oracle SQL写法与优化器缺陷一例
扩展Ribbon支持Nacos权重的三种方式
Golang學習筆記—結構體
The road to systematic construction of geek planet business monitoring and alarm system
Agricultural futures account opening
Software testing - Test Case Design & detailed explanation of test classification
R language airpassengers dataset visualization
Oracle system/用户被锁定的解决方法
MYSQL 几个常用命令使用
Cryptography series: certificate format representation of PKI X.509
92-几个用match_recognize SQL写法示例
