题目描述

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

  1. # -*- coding:utf-8 -*-
  2. class Solution:
  3. def Sum_Solution(self, n):
  4. # write code here
  5. ans = n
  6. temp = ans and self.Sum_Solution(n-1)
  7. ans += temp
  8. return ans