Skip to content

Commit 53fe546

Browse files
author
sejineer
committed
validate-binary-search-tree solution
1 parent 5583d33 commit 53fe546

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
시간 복잡도: O(N)
3+
공간 복잡도: O(N)
4+
"""
5+
class Solution:
6+
def isValidBST(self, root: Optional[TreeNode]) -> bool:
7+
num_list = []
8+
9+
def dfs(node: TreeNode):
10+
if not node:
11+
return
12+
13+
dfs(node.left)
14+
num_list.append(node.val)
15+
dfs(node.right)
16+
17+
dfs(root)
18+
19+
mem = num_list[0]
20+
for i in range(1, len(num_list)):
21+
if mem >= num_list[i]:
22+
return False
23+
mem = num_list[i]
24+
return True

0 commit comments

Comments
 (0)