GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/python/098_Validate_Binary_Search_Tree.py at master · helenagithub/leetcode

Expand file tree

/

098_Validate_Binary_Search_Tree.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
40 lines (38 loc) · 1.26 KB
/

098_Validate_Binary_Search_Tree.py

Copy path

File metadata and controls

40 lines (38 loc) · 1.26 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
import sys
class Solution(object):
# def isValidBST(self, root):
# """
# :type root: TreeNode
# :rtype: bool
# """
# if root is None:
# return True
# order_list = self.getOrder(root)
# length = len(order_list)
# for i in range(length):
# if (i + 1) < length and order_list[i + 1] <= order_list[i]:
# return False
# return True
#
# def getOrder(self, node):
# result = []
# if node is None:
# return result
# result.extend(self.getOrder(node.left))
# result.append(node.val)
# result.extend(self.getOrder(node.right))
# return result
def isValidBST(self, root):
return self.isVaild_helper(root, -sys.maxint - 1, sys.maxint)
def isVaild_helper(self, root, minVal, maxVal):
if root is None:
return True
if root.val >= maxVal or root.val <= minVal:
return False
return self.isVaild_helper(root.left, minVal, root.val) and self.isVaild_helper(root.right, root.val, maxVal)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.