-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path938.二叉搜索树的范围和.py
More file actions
60 lines (57 loc) · 1.12 KB
/
938.二叉搜索树的范围和.py
File metadata and controls
60 lines (57 loc) · 1.12 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#
# @lc app=leetcode.cn id=938 lang=python
#
# [938] 二叉搜索树的范围和
#
# https://leetcode-cn.com/problems/range-sum-of-bst/description/
#
# algorithms
# Easy (75.08%)
# Likes: 56
# Dislikes: 0
# Total Accepted: 9.4K
# Total Submissions: 12.6K
# Testcase Example: '[10,5,15,3,7,null,18]\n7\n15'
#
# 给定二叉搜索树的根结点 root,返回 L 和 R(含)之间的所有结点的值的和。
#
# 二叉搜索树保证具有唯一的值。
#
#
#
# 示例 1:
#
# 输入:root = [10,5,15,3,7,null,18], L = 7, R = 15
# 输出:32
#
#
# 示例 2:
#
# 输入:root = [10,5,15,3,7,13,18,1,null,6], L = 6, R = 10
# 输出:23
#
#
#
#
# 提示:
#
#
# 树中的结点数量最多为 10000 个。
# 最终的答案保证小于 2^31。
#
#
#
# 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 rangeSumBST(self, root, L, R):
"""
:type root: TreeNode
:type L: int
:type R: int
:rtype: int
"""