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 d0b9e81 commit 568cec2Copy full SHA for 568cec2
LeetCode/Palindrome linked list.cpp
@@ -0,0 +1,29 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * struct ListNode {
4
+ * int val;
5
+ * ListNode *next;
6
+ * ListNode() : val(0), next(nullptr) {}
7
+ * ListNode(int x) : val(x), next(nullptr) {}
8
+ * ListNode(int x, ListNode *next) : val(x), next(next) {}
9
+ * };
10
+ */
11
+class Solution {
12
+public:
13
+ bool isPalindrome(ListNode* head) {
14
+ ListNode* temp=head;
15
+ vector<int> v;
16
+ while(temp){
17
+ v.push_back(temp->val);
18
+ temp=temp->next;
19
+ }
20
+ int i=0, j=v.size()-1;
21
+ while(i<j){
22
+ if(v[i]==v[j]){
23
+ i++;
24
+ j--;
25
+ }else return false;
26
27
+ return true;
28
29
+};
0 commit comments