We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 06a3f3d commit 0e513b7Copy full SHA for 0e513b7
validate-binary-search-tree/delight010.swift
@@ -0,0 +1,19 @@
1
+class Solution {
2
+ private var prev: Int?
3
+
4
+ func isValidBST(_ root: TreeNode?) -> Bool {
5
+ inorder(root)
6
+ }
7
8
+ private func inorder(_ root: TreeNode?) -> Bool {
9
+ guard let root = root else { return true }
10
11
+ guard inorder(root.left) else { return false }
12
13
+ if let prev = prev, root.val <= prev { return false }
14
+ prev = root.val
15
16
+ return inorder(root.right)
17
18
+}
19
0 commit comments