Title Description
Seeking 1 + 2 + 3 + ... + n, requires multiplication and division can not be used, for, while, if, else, switch, case and keywords such as conditional statement (A B:? C).
Thinking
For connecting the two parts and a first part = 0, the second portion of the operation will not be carried out, this is called short-circuit
Note that the following statement is a = n and (...) n only used for the determination, if n! = 0, then a value that depends on the number of the back.
class Solution:
def Sum_Solution(self, n):
ans = n
ans = n and (ans + self.Sum_Solution(self,n-1))
return ans