当前位置:网站首页>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;}}; 边栏推荐
- 美味的石井饭
- 2022年8月的10篇论文推荐
- 直播课堂系统08-腾讯云对象存储和课程分类管理
- HighTec shortcut keys (Keys) setting location
- xshell (sed command)
- uni-app微信小程序——下拉多选框
- Black cat takes you to learn Makefile Part 12: Summary of common Makefile problems
- 【640. 求解方程】
- [SQL brush questions] Day3----Special exercises for common functions that SQL must know
- MySQL Advanced Commands
猜你喜欢

《DevOps围炉夜话》- Pilot - CNCF开源DevOps项目DevStream简介 - feat. PMC成员胡涛

基于交流潮流的电力系统多元件N-k故障模型研究(Matlab代码实现)【电力系统故障】

为什么一般公司面试结束后会说「回去等消息」,而不是直接告诉面试者结果?

链表中的节点每k个一组翻转

FPGA - Memory Resources of 7 Series FPGA Internal Structure -03- Built-in Error Correction Function

使用 Cloudreve 搭建私有云盘

BM13判断一个链表是否为回文结构

HighTec快捷键(Keys)设置位置

财务年报怎样翻译,为什么要选择专业翻译公司?

使用SylixOS虚拟串口,实现系统串口自由
随机推荐
黑猫带你学Makefile第13篇:Makefile编译问题合集
Web Reverse Lilac Garden
关于 DataFrame: 处理时间
What are the concepts, purposes, processes, and testing methods of interface testing?
链表中的节点每k个一组翻转
The perfect alternative to domestic Gravatar avatars Cravatar
深度学习之 12 循环神经网络RNN2
About DataFrame: Processing Time
Application of Spatial 3D Model Reconstruction Based on Pix4Dmapper - Spatial Analysis and Site Selection
《DevOps围炉夜话》- Pilot - CNCF开源DevOps项目DevStream简介 - feat. PMC成员胡涛
A shell script the for loop statements, while statement
Service - DHCP principle and configuration
2022.8.8 Selected Lectures on Good Topics (Number Theory Field)
shell (text printing tool awk)
如何保护 LDAP 目录服务中的用户安全?
黑猫带你学Makefile第11篇:当头文件a.h改变时,如何将所有依赖头文件a.h的.c文件都重新编译
【PCBA方案】电子握力测试仪方案she‘ji
unusual understanding
翻译科技论文,俄译中怎样效果好
Using SylixOS virtual serial port, serial port free implementation system