/**
 * struct ListNode {
 *  int val;
 *  struct ListNode *next;
 *  ListNode(int x) : val(x), next(nullptr) {}
 * };
 */
class Solution {
  public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param head ListNode类
     * @return bool布尔型
     */
    bool isPalindrome(ListNode* head) {
        // write code here
        vector<int>ve;
        while (head) {
            ve.push_back(head->val);
            head = head->next;
        }
        int n = ve.size();
        for (int i = 0; i < n / 2; ++i) {
            if (ve[i] != ve[n - i - 1])
                return false;
        }
        return true;
    }
};

一、题目考察的知识点

回文链表

二、题目解答方法的文字分析

直接把所有的数存进一个动态数组,然后从两头遍历,一一对比,看是否是回文

三、本题解析所用的编程语言

c++