What is the problem? I compile it at my Eclipse IDE and everything is fine. But at OJ not.


  • 0
    O

    What is wrong with the code? I compile it at my computer. Everything was fine. But at OJ I have the following runtime error:

    Runtime Error Message:	Line 15: java.lang.NullPointerException
    Last executed input:	{}, {}
    
     public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
                 ListNode list = l1, result = l1;
                 l1 = l1.next;
                 while (l1 != null && l2 != null) {
                	 if (l1.val <= l2.val) {
                		 list.next = l1;
                		 l1 = l1.next;
                	 } else {
                		 list.next = l2;
                		 l2 = l2.next;
                	 }
                	 list = list.next;
                 }
                 while (l1 != null) {
            		 list.next = l1;
            		 l1 = l1.next;
                	 list = list.next;
                 }
                 while (l2 != null) {
            		 list.next = l2;
            		 l2 = l2.next;
                	 list = list.next;
                 }
                 
                 return result;
             }

Log in to reply
 

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