Palindrome Linked List
Linked list
easy
Score: 20
Given the head
of a singly linked list, return 1
if it is a palindrome.
Class Node:
data (int)
next (Node)
Input Format
First Parameter - LinkedList node head
.
Output Format
Return 1
if list is palindrome, else return 0
.
Example 1 :
Input :
LinkedList : 1 2 1
Output :
1
Explanation :
The given linked list is 1 2 1 , which is a palindrome and Hence, the output is 1.
Example 2 :
Input :
1 2 3 4
Output :
0
Explanation :
The given linked list is 1 2 3 4 , which is not a palindrome and Hence, the output is 0.
Constraints:
- The number of nodes in the list is in the range [1, 105].
- 0 <= Node.val <= 9
- Expected Time Complexity: O(N)
- Expected Auxialliary Space Usage: O(1) (i.e. , you should not use the recursive stack space as well).