funcisValidBST2(_root: TreeNode?) -> Bool { var stack = [TreeNode]() var pre =Int.min var cur = root while (cur !==nil||!stack.isEmpty) { while cur !==nil { stack.append(cur!) cur = cur?.left } cur = stack.removeLast() if cur!.val <= pre { returnfalse } pre = cur!.val cur = cur?.right } returntrue }