mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
Merge pull request #1792 from Inmord/v5-dev-optimal-comb
当n = m时,C(n, m) = C(n, n) = 1。
This commit is contained in:
commit
9bae66f219
@ -38,12 +38,9 @@ public class Combination implements Serializable {
|
|||||||
* @return 组合数
|
* @return 组合数
|
||||||
*/
|
*/
|
||||||
public static long count(int n, int m) {
|
public static long count(int n, int m) {
|
||||||
if (0 == m) {
|
if (0 == m || n == m) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (n == m) {
|
|
||||||
return NumberUtil.factorial(n) / NumberUtil.factorial(m);
|
|
||||||
}
|
|
||||||
return (n > m) ? NumberUtil.factorial(n, n - m) / NumberUtil.factorial(m) : 0;
|
return (n > m) ? NumberUtil.factorial(n, n - m) / NumberUtil.factorial(m) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user