Question: 2. Bonus question: 5 points Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time?

2. Bonus question: 5 points Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time? The following is part of the code. You should try to design a main method to test the program and submit a runnable and complete program. * /** * 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; } * */ class Solution { public boolean is Palindrome(ListNode head) { } } Examples: Input: 1->2 Output: false Input: 1->2->2->1 Output: true
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
