题解:用sum就作弊了。递归
代码:
class Solution:
def func(self , n):
if n == 0:
return 0
else:
return n + self.func(n-1)
a = 100
s = Solution()
print(s.func(a))
输出:
5050
题解:用sum就作弊了。递归
代码:
class Solution:
def func(self , n):
if n == 0:
return 0
else:
return n + self.func(n-1)
a = 100
s = Solution()
print(s.func(a))
输出:
5050