当前位置:网站首页>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;}};
边栏推荐
猜你喜欢
【开源教程5】疯壳·开源编队无人机-飞控固件烧写
LeetCode-498 - Diagonal Traversal
12 Recurrent Neural Network RNN2 of Deep Learning
阿里云架构师金云龙:基于云XR平台的视觉计算应用部署
LeetCode-36-Binary search tree and doubly linked list
FPGA - Memory Resources of 7 Series FPGA Internal Structure -03- Built-in Error Correction Function
一篇文章教你Pytest快速入门和基础讲解,一定要看
What are the concepts, purposes, processes, and testing methods of interface testing?
合并k个已排序的链表
Huawei router clock near the drainage experiment (using stream strategy)
随机推荐
LeetCode-498 - Diagonal Traversal
Shell编程之条件语句(二)
字节跳动原来这么容易就能进去...
接口测试的概念、目的、流程、测试方法有哪些?
使用SylixOS虚拟串口,实现系统串口自由
LeetCode每日一题(1573. Number of Ways to Split a String)
BM13判断一个链表是否为回文结构
The Thread State,
shell(文本打印工具awk)
文件IO-缓冲区
阿里云新增三大高性能计算解决方案,助力生命科学行业快速发展
美味的佳肴
2022.8.9 Mock Competition
这些不可不知的JVM知识,我都用思维导图整理好了
RADIUS Authentication Server Deployment Costs That Administrators Must Know
Service - DHCP principle and configuration
合并k个已排序的链表
Self-organization is a two-way journey between managers and members
《DevOps围炉夜话》- Pilot - CNCF开源DevOps项目DevStream简介 - feat. PMC成员胡涛
LeetCode-36-Binary search tree and doubly linked list