Kidding me? 0!=0?


  • 0
    Y
    public class Solution {
    public ListNode rotateRight(ListNode head, int n) {
     if(n==0) {
         return head;
    }
    else {  
        ListNode first,second;
        first=head;
        second=head;
        int i=0;
        while(i<n)
        {
            second=second.next;
        }
        while(second.next!=null)
        {
            first=first.next;
            second=second.next;
        }
        second.next=head;
        first.next=null;
      }
      return head;
    }
    

    }

    I got this error message:
    Runtime Error Message: Line 24: java.lang.NullPointerException
    Last executed input: {}, 0

    line 24 is
    second=second.next;

    If n=0, the it just return head, why it executed the else block?What the hell?


  • 0
    G

    I also get the same error message like you, I still don't know what's wrong with it.


  • 0
    Y

    This is the reply of the leetcode.

    Sorry, there is a bug in a recent change.

    Meanwhile the real last executed input that caused the Null pointer exception is: {}, 1.

    I will get this issue fixed soon, thanks for your patience.


  • 0
    Y

    I think the bug is solved now.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.