Skip to content

Commit

Permalink
Time: 14 ms (17.61%), Space: 74.8 MB (5.34%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-S-Sahu committed Oct 21, 2024
1 parent 85e0c42 commit e4d585b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 0234-palindrome-linked-list/0234-palindrome-linked-list.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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 {
ListNode curr;
public boolean isPalindrome(ListNode head) {
curr = head;
return reverseCheck(head);
}

public boolean reverseCheck(ListNode head) {
if (head == null) return true;
boolean ans = reverseCheck(head.next) && head.val == curr.val;
curr = curr.next;
return ans;
}
}

0 comments on commit e4d585b

Please sign in to comment.