grandyang / leetcode

Provide all my solutions and explanations in Chinese for all the Leetcode coding problems.
6.16k stars 737 forks source link

A little bug in No.2 Add two numbers #2014

Open Travelmind opened 3 years ago

Travelmind commented 3 years ago

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