mrlonelyjtr's blog

写BUG的程序猿


  • Home

  • Categories

  • Archives

  • Tags

  • Search

【剑指Offer】求1+2+...+n

Posted on 2017-09-05 | In Algorithm , 剑指Offer

题目

求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。

实现

1
2
3
4
5
public int Sum_Solution(int n) {
int sum = n;
boolean end = n > 0 && (sum += Sum_Solution(n - 1)) > 0;
return sum;
}
# Algorithm # OJ
【剑指Offer】圆圈中最后剩下的数字
【剑指Offer】不用加减乘除做加法
  • Table of Contents
  • Overview
mrlonelyjtr

mrlonelyjtr

间歇性踌躇满志,持续性混吃等死

780 posts
18 categories
18 tags
Github
  1. 1. 题目
  2. 2. 实现
© 2020 mrlonelyjtr
Powered by Hexo
Theme - NexT.Pisces