We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fd09810 commit 85b6371Copy full SHA for 85b6371
Linked List/linked_list_pallindrome.cpp
@@ -0,0 +1,33 @@
1
+
2
+/**
3
+ * Definition for singly-linked list.
4
+ * struct ListNode {
5
+ * int val;
6
+ * ListNode *next;
7
+ * ListNode() : val(0), next(nullptr) {}
8
+ * ListNode(int x) : val(x), next(nullptr) {}
9
+ * ListNode(int x, ListNode *next) : val(x), next(next) {}
10
+ * };
11
+ */
12
+class Solution {
13
+public:
14
+ bool isPalindrome(ListNode* head) {
15
+ vector<int> contents;
16
+ while(head != NULL) {
17
+ int val = head->val;
18
+ contents.push_back(val);
19
+ head = head->next;
20
+ }
21
+ int low = 0, high = contents.size() - 1;
22
+ while(low <= high) {
23
+ if(contents[low] == contents[high]){
24
+ low++;
25
+ high--;
26
27
+ else {
28
+ return false;
29
30
31
+ return true;
32
33
+};
0 commit comments