The while condition should add carry != 0, like this: while( l1 != null || l2 != null || carry ==1){ } otherwise, it cannot pass the test case like: [9,9,9,9,9,9,9] [9,9,9,9] output should be: [8,9,9,9,0,0,0,1] but it missed the highest [1] thx