# Palindrome Linked List LeetCode Solution | Easy Approach Share:

Palindrome Linked List Given the `head` of a singly linked list, return `true` if it is a palindrome.

Example 1:

```Input: head = [1,2,2,1]
Output: true
```

Example 2:

```Input: head = [1,2]
Output: false
```

Constraints:

• The number of nodes in the list is in the range `[1, 105]`.
• `0 <= Node.val <= `

Time: O(n)
Space: O(1)

### C++

``````class Solution {
public:

while (fast && fast->next) {
slow = slow->next;
fast = fast->next->next;
}

if (fast)
slow = slow->next;
slow = reverseList(slow);

while (slow) {
return false;
slow = slow->next;
}

return true;
}

private:
ListNode* prev = nullptr;

}

return prev;
}
};``````

### Java

`````` class Solution {

while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
}

if (fast != null)
slow = slow.next;
slow = reverseList(slow);

while (slow != null) {
return false;
slow = slow.next;
}

return true;
}

ListNode prev = null;

}

return prev;
}
}
``````

### Python

``````
class Solution:
def isPalindrome(self, head: ListNode) -> bool:
prev = None

while curr:
next = curr.next
curr.next = prev
prev = curr
curr = next

return prev

while fast and fast.next:
slow = slow.next
fast = fast.next.next

if fast:
slow = slow.next
slow = reverseList(slow)

while slow: