Here is my solution?please tell my why it run solwly?Thanks


  • 0
    P

    i have a question.Why my JAVA programe so slowly?Here is my code.Thanks

    Runtime: 65 ms
     public  ListNode addTwoNumbers(ListNode a, ListNode b) {	
          	ListNode r = new ListNode(0);
          	ListNode result = r;
          	int jin=0;
          	for(;a!=null||b!=null||jin!=0;r=r.next,a = a==null?null:a.next,b = b==null?null:b.next)
          	{
          		int i=a==null?0:a.val;
          		int j=b==null?0:b.val;
          		r.next=new ListNode((i+j+jin*10)%10);
          		jin=(i+j+jin)/10;
          	}
          	return result.next;
            
        }
    

Log in to reply
 

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