fork download
  1. /**
  2.  * Definition for singly-linked list.
  3.  * public class ListNode {
  4.  * int val;
  5.  * ListNode next;
  6.  * ListNode() {}
  7.  * ListNode(int val) { this.val = val; }
  8.  * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  9.  * }
  10.  */
  11. class Solution {
  12.  
  13. public static ListNode reverseLL(ListNode head) {
  14.  
  15. ListNode cur = head;
  16. ListNode prev = null;
  17. ListNode next = null;
  18.  
  19. while (cur != null) {
  20.  
  21. next = cur.next;
  22. cur.next = prev;
  23. prev = cur;
  24. cur = next;
  25. }
  26.  
  27. return prev;
  28. }
  29.  
  30.  
  31. public static ListNode midPointLL (ListNode head) {
  32.  
  33. ListNode slow = head;
  34. ListNode fast = head;
  35.  
  36. while (fast.next != null && fast.next.next != null) {
  37.  
  38. slow = slow.next;
  39. fast = fast.next.next;
  40. }
  41.  
  42. return slow;
  43. }
  44.  
  45.  
  46. public boolean isPalindrome(ListNode head) {
  47.  
  48. ListNode midNode = midPointLL(head);
  49.  
  50. ListNode temp = midNode.next;
  51.  
  52. midNode.next = null;
  53.  
  54. ListNode newHead = reverseLL(temp);
  55.  
  56. ListNode t1 = head;
  57. ListNode t2 = newHead;
  58.  
  59. while (t1 != null && t2 != null) {
  60.  
  61. if (t1.val != t2.val)
  62. return false;
  63.  
  64. t1 = t1.next;
  65. t2 = t2.next;
  66. }
  67.  
  68.  
  69. return true;
  70. }
  71. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:13: error: cannot find symbol
    public static ListNode reverseLL(ListNode head) {
                                     ^
  symbol:   class ListNode
  location: class Solution
Main.java:13: error: cannot find symbol
    public static ListNode reverseLL(ListNode head) {
                  ^
  symbol:   class ListNode
  location: class Solution
Main.java:31: error: cannot find symbol
    public static ListNode midPointLL (ListNode head)  {
                                       ^
  symbol:   class ListNode
  location: class Solution
Main.java:31: error: cannot find symbol
    public static ListNode midPointLL (ListNode head)  {
                  ^
  symbol:   class ListNode
  location: class Solution
Main.java:46: error: cannot find symbol
    public boolean isPalindrome(ListNode head) {
                                ^
  symbol:   class ListNode
  location: class Solution
Main.java:15: error: cannot find symbol
        ListNode cur = head;
        ^
  symbol:   class ListNode
  location: class Solution
Main.java:16: error: cannot find symbol
        ListNode prev = null;
        ^
  symbol:   class ListNode
  location: class Solution
Main.java:17: error: cannot find symbol
        ListNode next = null;
        ^
  symbol:   class ListNode
  location: class Solution
Main.java:33: error: cannot find symbol
        ListNode slow = head;
        ^
  symbol:   class ListNode
  location: class Solution
Main.java:34: error: cannot find symbol
        ListNode fast = head;
        ^
  symbol:   class ListNode
  location: class Solution
Main.java:48: error: cannot find symbol
        ListNode midNode = midPointLL(head);
        ^
  symbol:   class ListNode
  location: class Solution
Main.java:50: error: cannot find symbol
        ListNode temp = midNode.next;
        ^
  symbol:   class ListNode
  location: class Solution
Main.java:54: error: cannot find symbol
        ListNode newHead = reverseLL(temp);
        ^
  symbol:   class ListNode
  location: class Solution
Main.java:56: error: cannot find symbol
        ListNode t1 = head;
        ^
  symbol:   class ListNode
  location: class Solution
Main.java:57: error: cannot find symbol
        ListNode t2 = newHead;
        ^
  symbol:   class ListNode
  location: class Solution
15 errors
stdout
Standard output is empty