> For the complete documentation index, see [llms.txt](https://lex47.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lex47.gitbook.io/leetcode/leet-solution-ruby/234.md).

# 234. Palindrome Linked List

Given a singly linked list, determine if it is a palindrome.

**Example 1:**

```
Input: 1->2
Output: false
```

**Example 2:**

```
Input: 1->2->2->1
Output: true
```

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

```
# Definition for singly-linked list.
# class ListNode
#     attr_accessor :val, :next
#     def initialize(val = 0, _next = nil)
#         @val = val
#         @next = _next
#     end
# end
# @param {ListNode} head
# @return {Boolean}
def is_palindrome(head)
  return true if head.nil?
  data = []
  while(!head.nil?)
    data << head.val
    head = head.next
  end
  data == data.reverse
end
```
