-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path669.py
More file actions
27 lines (26 loc) · 754 Bytes
/
Copy path669.py
File metadata and controls
27 lines (26 loc) · 754 Bytes
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
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def trimBST(self, root, L, R):
"""
:type root: TreeNode
:type L: int
:type R: int
:rtype: TreeNode
"""
if root == None:
return None;
if root.val < L:
root = root.right;
return self.trimBST(root, L, R);
elif root.val > R:
root = root.left;
return self.trimBST(root, L, R);
else:
root.left = self.trimBST(root.left, L, R);
root.right = self.trimBST(root.right, L, R);
return root;