Skip to content

Commit 7a4de8d

Browse files
necankeon
authored andcommitted
fix a error in is_bst.py (keon#474)
1 parent bab335a commit 7a4de8d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

algorithms/tree/bst/is_bst.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@
2020
Binary tree [1,2,3], return false.
2121
"""
2222

23-
2423
def is_bst(root):
2524
"""
2625
:type root: TreeNode
2726
:rtype: bool
2827
"""
29-
if not root:
30-
return True
28+
3129
stack = []
3230
pre = None
33-
while root and stack:
31+
32+
while root or stack:
3433
while root:
3534
stack.append(root)
3635
root = root.left
@@ -39,4 +38,5 @@ def is_bst(root):
3938
return False
4039
pre = root
4140
root = root.right
41+
4242
return True

0 commit comments

Comments
 (0)