快慢指针法找到链表中点。
struct ListNode*slow=head,*fast=head;
while(fast&&fast->next){
slow=slow->next;
fast=fast->next->next;
}
链表翻转方法
struct ListNode*cur=head;
struct ListNode*pre=NULL;
while(cur){
struct ListNode*temp=cur->next;
cur->next=pre;
pre=cur;
cur=temp;
}
组合起来可用于判断链表回文
本文介绍了一种使用快慢指针法查找链表中点的方法,以及链表的翻转技巧。快慢指针法适用于寻找链表的中间节点,而链表翻转则通过迭代方式实现。这些技巧组合起来可以用于判断链表是否为回文。
&spm=1001.2101.3001.5002&articleId=104186200&d=1&t=3&u=e8c85eb5dcc940629e036b413c068a17)
1304

被折叠的 条评论
为什么被折叠?



