剑指offer64:求1+2+…+n python 题目描述解法 题目描述 解法 利用逻辑运算 class Solution: def __init__(self): self.res = 0 def sumNums(self, n: int) -> int: n > 1 and self.sumNums(n-1) #对于and如果为真,返回后面的表达式,对于or,如果为真,返回前面的表达式 self.res += n return self.res