题解 | #求1+2+3+...+n#

求1+2+3+...+n

http://www.nowcoder.com/practice/7a0da8fc483247ff8800059e12d7caf1

题目:求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
思路:递归完事

public class Solution {
    public int Sum_Solution(int n) {
        return fun(n);
    }
    public int fun(int n){
        if(n==0){
            return 0;
        }
        return n+fun(n-1);
    }
}
全部评论

相关推荐

我:“加班需要有加班工资。” hr:“为什么?” 哈哈哈哈哈哈哈离大谱
juntenor:你确实太理想化了,对社会不了解呀。这个和HR没有关系,这是国内特色,不然怎么还会有外包就这种逆天的存在呢。
点赞 评论 收藏
分享
05-05 21:45
已编辑
广州大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务