当前位置:网站首页>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;}};
边栏推荐
猜你喜欢
Live Classroom System 08-Tencent Cloud Object Storage and Course Classification Management
管理员必须知道的RADIUS认证服务器的部署成本
ThreadLocal全面解析(一)
String类的常用方法
测试4年感觉和1、2年时没什么不同?这和应届生有什么区别?
服务——DHCP原理与配置
威纶通触摸屏如何在报警的同时,显示出异常数据的当前值?
基于交流潮流的电力系统多元件N-k故障模型研究(Matlab代码实现)【电力系统故障】
Service - DNS forward and reverse domain name resolution service
shell脚本循环语句for、while语句
随机推荐
Black cat takes you to learn Makefile Part 12: Summary of common Makefile problems
IM 即时通讯开发如何设计图片文件的服务端存储架构
win系统下pytorch深度学习环境安装
电力系统潮流计算(牛顿-拉夫逊法、高斯-赛德尔法、快速解耦法)(Matlab代码实现)
Using SylixOS virtual serial port, serial port free implementation system
文件IO-缓冲区
2022年8月10日:使用 ASP.NET Core 为初学者构建 Web 应用程序--使用 ASP.NET Core 创建 Web UI(没看懂需要再看一遍)
2022年8月的10篇论文推荐
shell编程之免交互
华为路由器旁挂引流实验(使用流策略)
ThreadLocal comprehensive analysis (1)
The Thread State,
labelme - block drag and drop events
Shell programming specification and variables
ThreadLocal全面解析(一)
3D model reconstruction of UAV images based on motion structure restoration method based on Pix4Dmapper
BM13判断一个链表是否为回文结构
ASCII、Unicode和UTF-8
Exploration and practice of the "zero trust" protection and data security governance system of the ransomware virus of Meichuang Technology
华为HCIE云计算之Fusion Access桌面云