Help me to find the key !

  • 0

    I just want to know that why the solution I coding below doesn`t work, me!

    public class Solution {
        public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
            ListNode ln = new ListNode(0);
            int temp;
            while(null != && null !={
                ln.val = ln.val + (l1.val + l2.val)%10;
                temp = (l1.val + l2.val)/10;
       = new ListNode(temp);
                ln =;
                l1 =;
                l2 =;
            return ln;

  • 0

    In my opinion,firstly,your return sentence is wrong.Because your ln pointer has pointed the tail of the list.So you should state another pointer.For example:below your third line to add ListNode test = ln;finally,return test;then,you should modify your while()

Log in to reply

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