package
Version:
v0.0.11
Opens a new window with list of versions in this module.
Published: Mar 4, 2025
License: GPL-3.0
Opens a new window with license information.
Imports: 2
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
Documentation
¶
func Comb(data []interface{}, k int) [][]interface{}
*
- 获得从 m 中取 n 的所有组合
- 思路如下:
- 生成一个长度为 m 的数组,
- 数组元素的值为 1 表示其下标代表的数被选中,为 0 则没选中。
*
- 1. 初始化数组,前 n 个元素置 1,表示第一个组合为前 n 个数;
- 2. 从左到右扫描数组元素值的 “10” 组合,找到第一个 “10” 组合后将其变为 “01” 组合;
- 3. 将其左边的所有 “1” 全部移动到数组的最左端
- 4. 当 n 个 “1” 全部移动到最右端时(没有 “10” 组合了),得到了最后一个组合。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.