我是靠谱客的博主 酷炫酸奶,这篇文章主要介绍两数之和--python ->的意思,现在分享给大家,希望可以做个参考。

class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
#List = []
n = len(nums)
for x in range(n):
for y in range(x+1,n):
if nums[y] == target - nums[x]:
return x,y
break
else:
continue

class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:

->List[int] 是什么意思?
->常常出现在python函数定义的函数名后面,为函数添加元数据,描述函数的返回类型,从而方便开发人员使用。

def add(x, y) -> int:
return x+y

这里面,元数据表明了函数的返回值为int类型。
这样做的好处:使用预期的类型来注释参数,然后在函数返回值验证时检验参数的类型或者将其强制转换成预期的类型。

最后

以上就是酷炫酸奶最近收集整理的关于两数之和--python ->的意思的全部内容,更多相关两数之和--python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(139)

评论列表共有 0 条评论

立即
投稿
返回
顶部