当前位置:网站首页>Leetcode-234-palindrome linked list
Leetcode-234-palindrome linked list
2022-06-29 15:48:00 【z754916067】
subject

Ideas
- Linked list is not palindrome , It means that the number may be palindromed . The most direct method is to traverse the array and then judge whether the array returns a palindrome , But such words are too violent and should not be the solution they want .
- The beginning of palindromes has a feature : The next one is equal to yourself .
- incorrect , It may not be equal , But according to the middle node symmetry …
- It suddenly occurred to me whether I could use the stack , Push the traversal number onto the stack , The stack will pop up while traversing from the beginning , Just judge whether the numbers are equal . But it always feels like the most violent solution .
Code
public boolean isPalindrome(ListNode head) {
Stack<Integer> s = new Stack<>();
ListNode temp = head;
while(temp!=null){
s.push(temp.val);
temp=temp.next;
}
// Start comparing Re traversal
while(head.next!=null){
if(head.val!=s.pop()) return false;
head=head.next;
}
return true;
}
边栏推荐
猜你喜欢

火山引擎入选国内首个《边缘计算产业全景图》

在shop工程中,实现一个菜单(增删改查)

EasyGBS调用获取实时快照接口时,出现白色方块该如何解决?

Imgutil image processing tool class, text extraction, image watermarking

LeetCode-234-回文链表

cmake学习-2

89.(cesium篇)cesium聚合图(自定义图片)

Business Intelligence BI and business management decision-making thinking No. 3: business quality analysis

GWD: rotating target detection based on Gaussian Wasserstein distance | ICML 2021

List集合详细讲解
随机推荐
Dynamically listening for DOM element height changes
swift JSONSerialization
Huawei cloud AOM version 2.0 release
动态监听DOM元素高度变化
雷达相关内容简介
极化SAR几种成像模式
Training mode of deep learning network
13.TCP-bite
雷达基本组成
动作捕捉系统用于苹果采摘机器人
Flink SQL task taskmanager memory settings
上次给我们发福利的 TDesign ,今天讲讲它的开源故事
雷达天线简介
复数卷积神经网络:CV-CNN
Leetcode notes: Weekly contest 299
swift JSONSerialization
Deeply understand promise's hand and teach you to write a version
Stlink troubleshooting
LeetCode-470-用Rand7()实现Rand10()
「游戏引擎 浅入浅出」98. SubstancePainter插件开发