aboutsummaryrefslogtreecommitdiffstats
path: root/234/main.cpp
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-04-04 16:36:22 +0000
committerterminaldweller <thabogre@gmail.com>2022-04-04 16:36:22 +0000
commit2fe0e87bd53f221b58ff862b1db3ce6f5bd5217c (patch)
tree2a2335d2ac1a702ecdbe0ebe4e481af50b433e4c /234/main.cpp
parentadded 13 (diff)
downloadleetcode-2fe0e87bd53f221b58ff862b1db3ce6f5bd5217c.tar.gz
leetcode-2fe0e87bd53f221b58ff862b1db3ce6f5bd5217c.zip
update
Diffstat (limited to '234/main.cpp')
-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; }