1、原题目
![](https://i-blog.csdnimg.cn/blog_migrate/1c54884bdd99548643d0d96ce6d3f231.png)
2、解答
![](https://i-blog.csdnimg.cn/blog_migrate/a3edf86d39e5c669f75a034d936c36d1.png)
3、需要注意的地方
新人学python之后做题目往往会遇到这种困难,就是碰到自己不认识的语法结构。
比如这句:def runningSum(self, nums: List[int]) -> List[int]
What?我从来没有见过这个。
于是,上网找了一下,找到了官方文档
https://docs.python.org/3.5/library/typing.html
![](https://i-blog.csdnimg.cn/blog_migrate/8d2e6dbc64abe6a44df90bc5f789c35c.png)
这是一种类型提示,在python3.5及以后版本被使用,目的是告诉你,nums是一个数组类型,其中的元素是int类型。
所以,只需要在代码首部导入类型模块
from typing import List
实现效果如下:
![](https://i-blog.csdnimg.cn/blog_migrate/75ae1db2b3c25392efd4667bc4d8701e.png)