Merge pull request #1792 from Inmord/v5-dev-optimal-comb

当n = m时,C(n, m) = C(n, n) = 1。
This commit is contained in:
Golden Looly 2021-08-26 23:47:51 +08:00 committed by GitHub
commit 9bae66f219
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,12 +38,9 @@ public class Combination implements Serializable {
* @return 组合数
*/
public static long count(int n, int m) {
if (0 == m) {
if (0 == m || n == m) {
return 1;
}
if (n == m) {
return NumberUtil.factorial(n) / NumberUtil.factorial(m);
}
return (n > m) ? NumberUtil.factorial(n, n - m) / NumberUtil.factorial(m) : 0;
}