当前位置:网站首页>BM13 determines whether a linked list is a palindrome
BM13 determines whether a linked list is a palindrome
2022-08-10 22:29:00 【dry rice white】
There are many solutions to this water problem:
I wrote it directly with the stack, so I won't explain the idea too much
There are only a few lines of code in total, and you can understand it with your eyes closed
Optimizable memory: only push the general stack, anyway, I don't think it is necessary to do so, if the topic has memory constraints, it can be optimized
/*** struct ListNode {* int val;* struct ListNode *next;* };*/class Solution {public:/**** @param head ListNode class the head* @return bool boolean*/bool isPail(ListNode* head) {// write code here//Write okk directly on the stackstacksta;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;}};
边栏推荐
- FPGA - 7系列 FPGA内部结构之Memory Resources -03- 内置纠错功能
- QT笔记——QT工具uic,rcc,moc,qmake的使用和介绍
- ThreadLocal comprehensive analysis (1)
- Use Cloudreve to build a private cloud disk
- What is Jmeter? What are the principle steps used by Jmeter?
- 3598. 二叉树遍历(华中科技大学考研机试题)
- port forwarding
- 华为路由器旁挂引流实验(使用流策略)
- 【开源教程5】疯壳·开源编队无人机-飞控固件烧写
- Shell编程规范与变量
猜你喜欢
QT笔记——vs + qt 创建一个带界面的 dll 和 调用带界面的dll
Use Cloudreve to build a private cloud disk
罗克韦尔AB PLC RSLogix5000中计数器指令使用方法介绍
camera预览流程 --- 从HAL到OEM
阿里云新增三大高性能计算解决方案,助力生命科学行业快速发展
c语言之 练习题1 大贤者福尔:魔法数,神奇的等式
mmpose关键点(一):评价指标(PCK,OKS,mAP)
C#【必备技能篇】Hex文件转bin文件的代码实现
翻译科技论文,俄译中怎样效果好
Live Classroom System 08 Supplement - Tencent Cloud Object Storage and Course Classification Management
随机推荐
xshell (sed 命令)
HighTec shortcut keys (Keys) setting location
LeetCode-498 - Diagonal Traversal
c语言之 练习题1 大贤者福尔:魔法数,神奇的等式
Service - DNS forward and reverse domain name resolution service
艺术与科技的狂欢,阿那亚2022砂之盒沉浸艺术季
QT笔记——用VS + qt 生成dll 和 调用生成的dll
STL-stack
camera预览流程 --- 从HAL到OEM
商家招募电商主播要考虑哪些内容
合并k个已排序的链表
LeetCode每日一题(1573. Number of Ways to Split a String)
What are the concepts, purposes, processes, and testing methods of interface testing?
罗克韦尔AB PLC RSLogix5000中计数器指令使用方法介绍
《DevOps围炉夜话》- Pilot - CNCF开源DevOps项目DevStream简介 - feat. PMC成员胡涛
Black cat takes you to learn Makefile Part 12: Summary of common Makefile problems
3D model reconstruction of UAV images based on motion structure restoration method based on Pix4Dmapper
交换机和生成树知识点
The Thread State,
Alibaba and Ant Group launched OceanBase 4.0, a distributed database, with single-machine deployment performance exceeding MySQL