MCPcopy Create free account
hub / github.com/algorithm004-01/algorithm004-01 / Do

Method Do

Week 02/id_171/CombinationsSol.cs:66–83  ·  view source on GitHub ↗

使用回溯。 假设1到n是所有能使用的数字,k是要组成k个元素的列表 每一次递归的时候,判断临时容器中数字是否已经够了,如果够了,就加入到结果集中。 递归方法中有层级和开始数字这两个人重要参数。 最开始进入代码时,开始数字是1,层级是1,进行循环,此时循环能达到最大数字是n - (k - level),将循环当前数字加入到临时容器中, 开始数字和层级加1,进入递归,当前数字的递归结束之后,将当数字移除。 进入下一个循环 </para

(int n, int k, int start, int level, List<int> container, IList<IList<int>> result)

Source from the content-addressed store, hash-verified

source not stored for this graph (policy: none)

Callers

nothing calls this directly

Calls 1

AddMethod · 0.80

Tested by

no test coverage detected