Skip to content

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

Description

@zengfang55

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 ;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions