题目
代码
思路:
由于题目中显示说明,不能使用乘除法, for while if 等,对于我们解题给出了很多限制,所以不能使用常规的方法进行解题,这里我们采用递归的方式
执行用时:48 ms, 在所有 Python3 提交中击败了46.88% 的用户
内存消耗:24.7 MB, 在所有 Python3 提交中击败了13.32% 的用户
通过测试用例:35 / 35
class Solution:
def sumNums(self, n: int) -> int:
return 0 if n==0 else n+self.sumNums(n-1)