Given a singly linked list, determine if it is a palindrome. 1234567891011121314151617181920212223 bool (struct ListNode* head) { int a [1000000]; int count=0; while(head){ a[count]=head->val; head=head->next; count++; } int flag=0; int cishu=count/2; for(int i=0;i<cishu;i++){ if(a[i]!=a[count-i-1]){ flag=1; break; } } if(flag==1){ return false; } return true;} 赞微海报分享
近期评论