diff --git a/Others/Palindrome linkedlist.cpp b/Others/Palindrome linkedlist.cpp new file mode 100644 index 00000000..fc92110d --- /dev/null +++ b/Others/Palindrome linkedlist.cpp @@ -0,0 +1,27 @@ +/** + * Definition for singly-linked list. + * 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: + bool isPalindrome(ListNode* head) { + vectorvec; + ListNode* temp = head; + while (temp!=nullptr){ + vec.push_back(temp->val); + temp=temp->next ; + } + for (int i =0 ;i