擅长:python、mysql、java
<p>当你说<code>temp += ...</code>时,你正在修改<code>temp</code>。但你在左右两种情况下都用它。你知道吗</p>
<p>所以你有:</p>
<pre><code>temp = [0]
if root.left is not None:
temp += [1] # Now temp is [0, 1], probably okay
...
if root.right is not None:
temp += [2] # Now temp is [0, 1, 2], not [0, 2]!
</code></pre>