388. Palindrome Linked List (O(1) Space)

MediumLinked ListTwo PointersLinked List

Given a singly linked list, return true if it reads the same forwards and backwards, using O(1) extra space (beyond the input). Return a boolean.

Input: An array of node values.

Output: Boolean — true or false.

Examples

Example 1
Input: [1,2,2,1]
Output: true
Explanation: Reads the same both ways.
Example 2
Input: [1,2,3,2,1]
Output: true
Explanation: Odd-length palindrome.
Example 3
Input: [1,2]
Output: false
Explanation: Not a palindrome.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →