aboutsummaryrefslogtreecommitdiffstats
path: root/234/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--234/main.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/234/main.cpp b/234/main.cpp
new file mode 100644
index 0000000..229bd28
--- /dev/null
+++ b/234/main.cpp
@@ -0,0 +1,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; }