题目考察的知识点:与链表有关的题基本都是插入,删除,交换顺序等,解决这些问题通常将链表的指针进行修改。
题目分析:可以将链表中的数据保存到一个vector数组中,然后判断这个数组是否回文。
本题解析所用的编程语言:c++
bool isPalindrome(ListNode* head) { // write code here vector<int> v; while (head) { v.push_back(head->val); head = head->next; } for (int i = 0, j = v.size() - 1; i < j; ++i, --j) if (v[i] != v[j]) return false; return true; }