牛客网LeetCode:求1+2+3+...+n

求1+2+3+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。

# -*- coding:utf-8 -*-
class Solution:
    def __init__(self):
        self.sum = 0
    def Sum_Solution(self, n):
        # write code here
        def get_sum(n):
            self.sum += n
            n -= 1
            return n>0 and self.Sum_Solution(n)
        get_sum(n)
        return self.sum

猜你喜欢

转载自blog.csdn.net/weixin_38246633/article/details/83501217