当前位置:网站首页>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;
}
};
边栏推荐
- 力扣215题,数组中的第K个最大元素
- camera preview process --- from HAL to OEM
- 接口测试的概念、目的、流程、测试方法有哪些?
- Huawei router clock near the drainage experiment (using stream strategy)
- 什么是Jmeter?Jmeter使用的原理步骤是什么?
- APP UI自动化测试常见面试题,或许有用呢~
- Service - DNS forward and reverse domain name resolution service
- Shell编程之条件语句(二)
- 2022.8.9 模拟赛
- GMT,UTC,CST,DST,RTC,NTP,SNTP,NITZ: 嵌入式的时间
猜你喜欢
unusual understanding
美创科技勒索病毒“零信任”防护和数据安全治理体系的探索实践
Common interview questions for APP UI automation testing, maybe useful~
xshell (sed 命令)
Likou 221 questions, the largest square
Live Classroom System 09--Tencent Cloud VOD Management Module (1)
win系统下pytorch深度学习环境安装
String类的常用方法
LeetCode-498 - Diagonal Traversal
直播课堂系统08补-腾讯云对象存储和课程分类管理
随机推荐
Thread State 详解
Likou 221 questions, the largest square
ThreadLocal comprehensive analysis (1)
An article to teach you a quick start and basic explanation of Pytest, be sure to read
xshell (sed 命令)
2022.8.8 Selected Lectures on Good Topics (Number Theory Field)
美味的石井饭
“数据引擎”开启前装规模量产新赛道,「智协慧同」崭露头角
Shell 编程--Sed
JVM经典五十问,这下面试稳了
[SQL brush questions] Day3----Special exercises for common functions that SQL must know
为什么一般公司面试结束后会说「回去等消息」,而不是直接告诉面试者结果?
【PCBA solution】Electronic grip strength tester solution she'ji
C # Hex file transfer skills necessary article 】 【 bin file code implementation
过滤器
LeetCode-402-移掉K位数字
边缘与云计算:哪种解决方案更适合您的连接设备?
【开源教程5】疯壳·开源编队无人机-飞控固件烧写
shell programming without interaction
What is Jmeter? What are the principle steps used by Jmeter?