leetCode/src/main/java/com/leetcode/num/SumNums.java

22 lines
481 B
Java
Raw Normal View History

2020-11-15 06:26:19 +00:00
package com.leetcode.num;
2020-06-02 14:48:27 +00:00
/**
* @file SumNums.java
* @apiNote 1+2+...+n 要求不能使用乘除法forwhileifelseswitchcase等关键字及条件判断语句A?B:C
* https://leetcode-cn.com/problems/qiu-12n-lcof/
* @author zeekling
* @version
* @date 2020-06-02
*/
public class SumNums{
public int sumNums(int n) {
2020-11-15 14:25:40 +00:00
@SuppressWarnings("unused")
boolean res = n > 0 && (n += sumNums(n-1)) > 0;
2020-06-02 14:48:27 +00:00
return n;
}
}