SDE Path

Check if Linked List Is a Palindrome

Medium

Check if Linked List Is a Palindrome

Determine whether a singly linked list reads the same forward and backward.

Input format

The first line contains N — the number of nodes. The second line contains the N node values in list order.

Output format

Print true if the list reads the same forward and backward, otherwise false.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
4
1 2 2 1
Expected output
true
Example 2
Input
3
1 2 3
Expected output
false