求1-2-n-中等
2025-4-20
| 2025-4-20
Words 190Read Time 1 min
type
status
date
slug
summary
tags
category
icon
password

题目:

1+2+...+n ,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/SNJvJP 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
示例 1:
示例 2:
限制:
  • 1 <= n <= 10000

思路:

  • 递归
  • 从最大的开始
  • 每次加的数-1
  • 递归终止的条件是n=0

代码:

结果:

notion image
image-20220216173045255
流之各种操作气球”的最大数量
Loading...