Merge pull request #1159 from akiyamaneko/combination_enhanced

基于#1153 重新做了优化,剔除了缓存,直接计算即可
This commit is contained in:
Golden Looly 2020-10-14 11:00:16 +08:00 committed by GitHub
commit 8c17979082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ import java.util.Arrays;
import java.util.List;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
/**
* 组合即C(n, m)<br>
@ -53,11 +54,10 @@ public class Combination implements Serializable {
* @return 组合数
*/
public static long countAll(int n) {
long total = 0;
for (int i = 1; i <= n; i++) {
total += count(n, i);
if (n < 0 || n > 63) {
throw new IllegalArgumentException(StrUtil.format("countAll must have n >= 0 and n <= 63, but got n={}", n));
}
return total;
return n == 63 ? Long.MAX_VALUE : (1L << n) - 1;
}
/**