"""
Definition of SegmentTreeNode:
class SegmentTreeNode:
def __init__(self, start, end, count):
self.start, self.end, self.count = start, end, count
self.left, self.right = None, None
"""
class Solution:
# @param root, start, end: The root of segment tree and
# an segment / interval
# @return: The count number in the interval [start, end]
def query(self, root, start, end):
# write your code here
self.ans = 0
self.my_query(root, start, end)
return self.ans
def my_query(self, root, start, end):
if root == None or start > root.end or end < root.start:
return
if start <= root.start and end >= root.end:
self.ans += root.count
return
self.my_query(root.left, start, end)
self.my_query(root.right, start, end)
LintCode:线段树的查询II
最新推荐文章于 2022-04-25 11:49:10 发布