null pointer exception

  • 0

    Hello everyone,

    I want to discuss my solution in which I am not using dummy node and in my code in line = there is a null pointer exception coming up. I think the h2 is null, can anyone please suggest me why this is happening because h2 points to the head node then why this is null??

    Following is my code

    ListNode h1 = head;
            ListNode h2 = head;
            ListNode current = head;
            int totalListCount = 1;
                h1 =;
            while(!=null ) {
                current =;
                totalListCount = totalListCount+1;
            int finalCount = totalListCount-n;
            for(int i=1;i<finalCount;i++) {
                h2 =;
            return head;

    I shall be waiting for your replies.


Log in to reply

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