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

21 lines
451 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.leetcode.num;
/**
* @file SumNums.java
* @apiNote 求 1+2+...+n 要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句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) {
boolean res = n > 0 && (n += sumNums(n-1)) > 0;
return n;
}
}