当前位置:网站首页>[palindrome structure of or36 linked list]
[palindrome structure of or36 linked list]
2022-06-22 21:06:00 【Cat star people who love Durian】
List of articles
One 、 Title Description
Two 、 Provide easy to read code diagram

3、 ... and 、 Title code
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) {} };*/
struct ListNode *findMid(struct ListNode*head)
{
struct ListNode* fast=head;
struct ListNode* slow=head;
while(fast&&fast->next)
{
slow=slow->next;
fast=fast->next->next;
}
return slow;
}
struct ListNode * reserve(struct ListNode*head)
{
struct ListNode*newHead=NULL;
struct ListNode*cur=head;
while(cur)
{
struct ListNode*next=cur->next;
cur->next=newHead;
newHead=cur;
cur=next;
}
return newHead;
}
class PalindromeList {
public:
bool chkPalindrome(ListNode* A) {
ListNode* mid=findMid(A);
ListNode*head=reserve(mid);
ListNode*rhead=head;
ListNode*Ahead=A;
while(rhead&&Ahead)
{
if(rhead->val!=Ahead->val)
{
return false;
}
else
{
rhead=rhead->next;
Ahead=Ahead->next;
}
}
return true;
}
};
The above is the whole content of this article , If there are mistakes in the article or something you don't understand , Communicate more with meow bloggers . Learn from each other and make progress . If this article helps you , Can give meow bloggers a concern , Your support is my biggest motivation .
边栏推荐
猜你喜欢

Easyclick fixed status log window

The access succeeds but an exception is thrown: could not find acceptable representation

what? You can't be separated by wechat

Introduction of neural network (BP) in Intelligent Computing

R language usarrests dataset visualization
How to calculate yoy and mom in MySQL

Visualization of R language penguins dataset
Gradle Build Cache引发的Task缓存编译问题

SwiftUI如何模拟视图发光增大的动画效果
Code to Image Converter | 代码生成漂亮图片工具
随机推荐
89-oracle SQL写法与优化器缺陷一例
EasyClick更新图库
EasyClick 固定状态日志窗口
How to use feign to construct multi parameter requests
Ribbon负载均衡
Gradle Build Cache引发的Task缓存编译问题
Code to image converter
Kotlin1.6.20新功能Context Receivers使用技巧揭秘
Golang learning notes - structure
【20. 有效的括号】
【142. 环形链表 II】
Huawei cloud releases Latin American Internet strategy
74-这类SQL优化,oracle输给了mysql,如何补救?
Lora technology -- Lora signal changes from data to Lora spread spectrum signal, and then from RF signal to data through demodulation
Introduction to JWT
程序员必看的学习网站
如何计算 R 中的基尼系数(附示例)
[proteus simulation] 74LS138 decoder water lamp
已解决:一个表中可以有多个自增列吗
[observation] innovation in the software industry has entered a "new cycle". How can we make a new start in the changing situation?
