Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 理解:“;def rangeSumBST(self,root:TreeNode,L:int,R:int)->;int:“;论leetcode_Python_Algorithm_Class - Fatal编程技术网

Python 理解:“;def rangeSumBST(self,root:TreeNode,L:int,R:int)->;int:“;论leetcode

Python 理解:“;def rangeSumBST(self,root:TreeNode,L:int,R:int)->;int:“;论leetcode,python,algorithm,class,Python,Algorithm,Class,我正在处理leetcode上的一些问题,我不理解他们编写的代码。例如,为什么有一个指向int(->int:)的箭头?我也不明白TreeNode的用途。是否只是为了验证输入 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None c

我正在处理leetcode上的一些问题,我不理解他们编写的代码。例如,为什么有一个指向int(->int:)的箭头?我也不明白TreeNode的用途。是否只是为了验证输入

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def rangeSumBST(self, root: TreeNode, L: int, R: int) -> int:

称为函数注释,请阅读此页

更详细地说,Python2.x有docstring,它允许您附加 不同类型对象的元数据字符串。这非常方便, 因此,Python3通过允许将元数据附加到 描述其参数和返回值的函数

没有先入为主的用例,但是政治公众人物建议了几个。一个 非常方便的一种方法是允许您使用参数的 期望类型;这样就很容易写出一个 验证批注或将参数强制为正确的类型。 另一个是允许参数特定的文档,而不是 将其编码为docstring

用户:Katriel

TreeNode
本身是二叉树数据结构的一部分,我不知道所提到的具体leetcode问题,但本质上树是由许多
TreeNode
组成的,它们通过变量
self.left
left.right
引用其他
TreeNodes
,这些名称用于模拟可视化二叉树的传统外观。他们只是定义了节点,这样您就可以理解在回答问题时需要什么类


这可能只是该问题的重复。@glibdud谢谢