aboutsummaryrefslogtreecommitdiffstats
path: root/234/main.cpp
blob: 229bd287f1729f165e786d35cb8c816de53e1045 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "header.hpp"

struct ListNode {
  int val;
  ListNode *next;
  ListNode() : val(0), next(nullptr) {}
  ListNode(int x) : val(x), next(nullptr) {}
  ListNode(int x, ListNode *next) : val(x), next(next) {}
};

class Solution {
public:
  Solution() = default;
  bool isPalindrome(ListNode *head) {
    auto iter = head;
    std::vector<int> pal;

    while (iter->next != nullptr) {
      pal.push_back(iter->val);
      iter = iter->next;
    }
    pal.push_back(iter->val);
    for (int i = pal.size(); i >= 0; i--) {
      if (head->val != pal[i]) {
        return false;
      }
      head = head->next;
    }
    return true;
  }
};

int main(int argc, char **argv) { return 0; }