【LeetCode】剑指 Offer 64. 求1+2+…+n
文章目录
package offer;
public class Solution64 {
public static void main(String[] args) {
int n = 9;
Solution64 solution = new Solution64();
System.out.println(solution.method(n));
}
private int method(int n){
boolean x = (n > 1) && (n += method(n - 1)) > 0;
return n;
}
}
//时间复杂度为 O(n)
//空间复杂度为 O(n)