面试题64. 求1+2+…+n(Leetcode每日一题-2020.06.02)
Problem
求 1+2+…+n ,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
Example1
输入: n = 3
输出: 6
Example2
输入: n = 9
输出: 45
Constraints
1 <= n <= 10000
Solution
逻辑短路+递归
class Solution {
public:
int sumNums(int n) {
n >= 1 &a
原创
2020-06-02 18:36:37 ·
184 阅读 ·
0 评论