234. Palindrome Linked List
Description
Given a singly linked list, determine if it is a palindrome.
Constraints
Approach
Links
GeeksforGeeks
YouTube
Examples
Input: 1->2
Output: false
Solutions
// Definition for singly-linked list.
public class ListNode {
int val;
ListNode next;
ListNode() {}
ListNode(int val) {
this.val = val;
}
ListNode(int val, ListNode next) {
this.val = val; this.next = next;
}
}
Follow up
Could you do it in O(n) time and O(1) space?
Last updated
Was this helpful?