题解 | #求1+2+3+...+n#
求1+2+3+...+n
http://www.nowcoder.com/practice/7a0da8fc483247ff8800059e12d7caf1
# -*- coding:utf-8 -*-
class Solution:
def __init__(self):
self.ret = 0
def Sum_Solution(self, n):
# write code here
self.ret += n
n and self.Sum_Solution(n-1)
return self.ret
class Solution:
def __init__(self):
self.ret = 0
def Sum_Solution(self, n):
# write code here
self.ret += n
n and self.Sum_Solution(n-1)
return self.ret