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

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

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

/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 * 
 * @param n int整型 
 * @return int整型
 */
export function Sum_Solution(n: number): number {
    // write code here
    (n !== 1) && (n += Sum_Solution(n - 1))
    return n
}

全部评论

相关推荐

你背过凌晨4点的八股文么:简历挂了的话会是流程终止,像我一样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务