Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public boolean isPalindrome(ListNode head) {
- if(head==null || head.next==null)
- {
- return true;
- }
- ListNode r=rev(head);
- while(head!=null && r!=null)
- {
- if(head.val!=r.val)
- {
- return false;
- }
- head=head.next;
- r=r.next;
- }
- return true;
- }
- public ListNode rev(ListNode head)
- {
- if(head==null || head.next==null)
- {
- return head;
- }
- ListNode a=rev(head.next);
- head.next.next=head;
- head.next=null;
- return a;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement