We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
原题链接
二叉搜索树需要满足以下三个条件:
const isValidBST = function(root) { let prev = -Infinity let result = true function inorder(root) { if (root === null) return inorder(root.left) if (root.val <= prev) { result = false return } prev = root.val inorder(root.right) } inorder(root) return result }
递归隐式地维护了一个栈,在迭代的时候我们需要显式地将这个栈模拟出来。
const isValidBST = function (root) { const stack = [] let prev = -Infinity while (root || stack.length) { while (root) { stack.push(root) root = root.left } root = stack.pop() if (root.val <= prev) { return false } prev = root.val root = root.right } return true }
The text was updated successfully, but these errors were encountered:
这个中序递归有问题。。
Sorry, something went wrong.
已修正
No branches or pull requests
原题链接
中序遍历
二叉搜索树需要满足以下三个条件:
递归
迭代
递归隐式地维护了一个栈,在迭代的时候我们需要显式地将这个栈模拟出来。
The text was updated successfully, but these errors were encountered: