剑指offer:求和

一、问题描述

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

二、代码实现:

class Solution:
    def Sum_Solution(self, n):
        if n ==0:
            return 0
        else:
            b=n and self.Sum_Solution(n-1)
            a=n+b
        return a
原文地址:https://www.cnblogs.com/liuxiangyan/p/14373832.html