问题描述
我正在反转(reverse
)链表,如果两者相等,则将其与原始列表进行比较。这是一个回文,否则就不是。
void reverse(ListNode *&N) //reversing the copy of linked list
{
ListNode *one,*two,*three;
one=N;
two=N;
three=NULL;
while(one)
{
one=one->next;
two->next= three;
three=two;
two=one;
}
N=three;
}
bool ispalindrome(ListNode* head)
{
ListNode* rev = head;
ListNode *temp=head;
reverse(rev);
while(temp) //checking if reverse and original are equal
{
if(rev->val!= temp->val)return false;
rev=rev->next;
temp=temp->next;
}
return true;
}
```C++
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)