Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit faeda4b

Browse files
Merge pull request youngyangyang04#2733 from shengyufan/master
更新0110平衡二叉树Python3迭代法精简版代码
2 parents 75313fa + 507d9e0 commit faeda4b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

‎problems/0110.平衡二叉树.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,13 @@ class Solution:
609609
while stack:
610610
node = stack.pop()
611611
if node:
612-
stack.append(node)
612+
stack.append(node)#
613613
stack.append(None)
614-
if node.left: stack.append(node.left)
615-
if node.right: stack.append(node.right)
614+
# 采用数组进行迭代,先将右节点加入,保证左节点能够先出栈
615+
if node.right: #
616+
stack.append(node.right)
617+
if node.left: #
618+
stack.append(node.left)
616619
else:
617620
real_node = stack.pop()
618621
left, right = height_map.get(real_node.left, 0), height_map.get(real_node.right, 0)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /