解题思路:递归
class Solution:
res = 0
def sumNums(self, n: int) -> int:
self.res += n
n and self.sumNums(n-1)
return self.res
解题思路:递归
class Solution:
res = 0
def sumNums(self, n: int) -> int:
self.res += n
n and self.sumNums(n-1)
return self.res