Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

暴力枚举Combinations代码添加cur和k比较条件,可以减少遍历次数 #104

Open
zengfang55 opened this issue Sep 8, 2020 · 0 comments

Comments

@zengfang55
Copy link

77题代码添加cur和k比较条件,可以减少遍历次数
if(cur == k){
result.add(new ArrayList<>(path));
}
// 时间复杂度受k影响,k从2到n,时间复杂度从O(n^2) 到 O(n!)
/*
n=5 k=2 比较 两次迭代路径,没加cur>k 判断时迭代次数更多。 当n越大越明显。这个便利路径是注释//path.remove(path.size()-1);这个代码后得到的
//123453454552345455345545
//123455 455 345545523455455345545
*/
if(cur > k){
return ;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant