当前位置:网站首页>BM13判断一个链表是否为回文结构
BM13判断一个链表是否为回文结构
2022-08-10 21:49:00 【干饭小白】

这种水题有很多种解法:
我直接用栈写的,思路就不过多解释了
一共就几行代码,闭着眼睛都能看明白
可优化内存:只将一般压入栈,反正我感觉没必要这么做,如果题目有内存限定可以优化下
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
class Solution {
public:
/**
*
* @param head ListNode类 the head
* @return bool布尔型
*/
bool isPail(ListNode* head) {
// write code here
//直接用栈写 okk
stack<int>sta;
ListNode *p = head;
while(p != nullptr)
{
sta.push(p->val);
p = p->next;
}
p = head;
while(p != nullptr)
{
if(p->val != sta.top())
{
break;
}
sta.pop();
p = p->next;
}
if(p == nullptr)
{
return true;
}
return false;
}
};边栏推荐
- VLAN huawei 三种模式
- Intelligent scheme design - intelligent rope skipping scheme
- 【PCBA方案设计】蓝牙跳绳方案
- 学会开会|成为有连接感组织的重要技能
- Shell编程之条件语句(二)
- HighTec shortcut keys (Keys) setting location
- Regular expression of shell programming and text processor
- 新一代网络安全防护体系的五个关键特征
- 【PCBA scheme design】Bluetooth skipping scheme
- Conditional Statements of Shell Programming (2)
猜你喜欢

接口测试的概念、目的、流程、测试方法有哪些?

12 Recurrent Neural Network RNN2 of Deep Learning

Thread State 详解

2022年8月的10篇论文推荐

使用SylixOS虚拟串口,实现系统串口自由

win系统下pytorch深度学习环境安装

阿里云张新涛:支持沉浸式体验应用快速落地,阿里云云XR平台发布

Live Classroom System 09--Tencent Cloud VOD Management Module (1)

IM 即时通讯开发如何设计图片文件的服务端存储架构

FPGA - Memory Resources of 7 Series FPGA Internal Structure -03- Built-in Error Correction Function
随机推荐
高数_复习_第5章:多元函数微分学
Extended Chinese Remainder Theorem
美创科技勒索病毒“零信任”防护和数据安全治理体系的探索实践
VLAN huawei 三种模式
测试4年感觉和1、2年时没什么不同?这和应届生有什么区别?
Use Cloudreve to build a private cloud disk
智能方案设计——智能跳绳方案
国内Gravatar头像的完美替代方案Cravatar
华为路由器旁挂引流实验(使用流策略)
服务——DNS正向反向域名解析服务
新一代网络安全防护体系的五个关键特征
JVM经典五十问,这下面试稳了
c语言之 练习题1 大贤者福尔:魔法数,神奇的等式
QT笔记——QT工具uic,rcc,moc,qmake的使用和介绍
Regular expression of shell programming and text processor
Huawei router clock near the drainage experiment (using stream strategy)
MySQL高级指令
An article to teach you a quick start and basic explanation of Pytest, be sure to read
shell脚本循环语句for、while语句
Translating scientific and technological papers, how to translate from Russian to Chinese