当前位置:网站首页>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;}};
边栏推荐
猜你喜欢
《DevOps围炉夜话》- Pilot - CNCF开源DevOps项目DevStream简介 - feat. PMC成员胡涛
翻译科技论文,俄译中怎样效果好
mmpose关键点(一):评价指标(PCK,OKS,mAP)
Black cats take you learn Makefile article 13: a Makefile collection compile problem
Likou 221 questions, the largest square
【Maui正式版】创建可跨平台的Maui程序,以及有关依赖注入、MVVM双向绑定的实现和演示
美创科技勒索病毒“零信任”防护和数据安全治理体系的探索实践
Live Classroom System 08 Supplement - Tencent Cloud Object Storage and Course Classification Management
RK3399平台开发系列讲解(内核驱动外设篇)6.35、IAM20680陀螺仪介绍
从斐波那契 - 谈及动态规划 - 优化
随机推荐
威纶通触摸屏如何在报警的同时,显示出异常数据的当前值?
接口测试的概念、目的、流程、测试方法有哪些?
RADIUS Authentication Server Deployment Costs That Administrators Must Know
12 Recurrent Neural Network RNN2 of Deep Learning
The Thread State,
测试4年感觉和1、2年时没什么不同?这和应届生有什么区别?
过滤器
阿里云张新涛:支持沉浸式体验应用快速落地,阿里云云XR平台发布
服务——DNS正向反向域名解析服务
2022.8.8 Selected Lectures on Good Topics (Number Theory Field)
win系统下pytorch深度学习环境安装
链表中的节点每k个一组翻转
什么是Jmeter?Jmeter使用的原理步骤是什么?
Black cat takes you to learn Makefile Part 11: When the header file a.h changes, how to recompile all the .c files that depend on the header file a.h
camera预览流程 --- 从HAL到OEM
【开源教程5】疯壳·开源编队无人机-飞控固件烧写
解码2022中国网安强星丨正向建、反向查,华为构建数字化时代的网络安全防线
智能方案设计——智能跳绳方案
APP UI自动化测试常见面试题,或许有用呢~
Black cats take you learn Makefile article 13: a Makefile collection compile problem