Class Solution

java.lang.Object
g0201_0300.s0234_palindrome_linked_list.Solution

public class Solution extends Object
234 - Palindrome Linked List.<p>Easy</p> <p>Given the <code>head</code> of a singly linked list, return <code>true</code> if it is a palindrome.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/03/03/pal1linked-list.jpg" alt="" /></p> <p><strong>Input:</strong> head = [1,2,2,1]</p> <p><strong>Output:</strong> true</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/03/03/pal2linked-list.jpg" alt="" /></p> <p><strong>Input:</strong> head = [1,2]</p> <p><strong>Output:</strong> false</p> <p><strong>Constraints:</strong></p> <ul> <li>The number of nodes in the list is in the range <code>[1, 10<sup>5</sup>]</code>.</li> <li><code>0 <= Node.val <= 9</code></li> </ul> <p><strong>Follow up:</strong> Could you do it in <code>O(n)</code> time and <code>O(1)</code> space?</p>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isPalindrome

      public boolean isPalindrome(ListNode head)