The problem is a difference between how you pass in A and B, and how leetcode does. As an artifact of the Java and C++ versions, the lists are assumed to be fixed in size, so while A is described as the empty list, it actually is the empty list followed by B.length 0s. The numbers m and n refer to the size of the described array, so A.length = m+n.

In the case you have presented, A=[0], m=0, B=[1], and n=1. These are the values actually passed into your function. i=0 < m is false, so the while loop is skipped, and then you append B onto A, resulting in A=[0,1]. Since leetcode knows the length of the expected array, it only looks at the first n+m=1 elements, or [0].