We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bab335a commit 7a4de8dCopy full SHA for 7a4de8d
algorithms/tree/bst/is_bst.py
@@ -20,17 +20,16 @@
20
Binary tree [1,2,3], return false.
21
"""
22
23
-
24
def is_bst(root):
25
26
:type root: TreeNode
27
:rtype: bool
28
29
- if not root:
30
- return True
+
31
stack = []
32
pre = None
33
- while root and stack:
+ while root or stack:
34
while root:
35
stack.append(root)
36
root = root.left
@@ -39,4 +38,5 @@ def is_bst(root):
39
38
return False
40
pre = root
41
root = root.right
42
return True
0 commit comments