剑指 Offer 64. 求1+2+…+n

//求 1+2+...+n ,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
class
Solution { //定义res 表示计算结果 int res = 0; public int sumNums(int n) { // 当 n = 1 时 n > 1 不成立 ,此时 “短路” ,终止后续递归 boolean tmp = n > 1 && sumNums(n - 1) > 1; res = res + n; return res; } }
原文地址:https://www.cnblogs.com/peanut-zh/p/14152853.html