# 234. Palindrome Linked List

#### Easy

***

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

&#x20;

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/03/03/pal1linked-list.jpg)

<pre><code>Input: head = [1,2,2,1]
<strong>Output:
</strong> true
</code></pre>

**Example 2:**

![](https://assets.leetcode.com/uploads/2021/03/03/pal2linked-list.jpg)

<pre><code>Input: head = [1,2]
<strong>Output:
</strong> false
</code></pre>

&#x20;

**Constraints:**

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

&#x20;

**Follow up:** Could you do it in `O(n)` time and `O(1)` space?

```python
class Solution:
    def isPalindrome(self, head: Optional[ListNode]) -> bool:
        s = ""
        t = ""
        def recursion(head):
            nonlocal s
            nonlocal t
            if not head:
                return 
            s += str(head.val)
            recursion(head.next)
            t += str(head.val)
        recursion(head)
        return s == t
        
```
