Combinations

点击量:562

Given two integers n and k, return all possible combinations of k numbers out of 1 … n.
For example,
If n = 4 and k = 2, a solution is:

[
[2,4],
[3,4],
[2,3],
[1,2],
[1,3],
[1,4],
]

这题没有什么特别的思路吧,递归遍历。代码如下:

     

原创不易,如果您觉得本文对您有帮助,可以打赏博主一杯咖啡,鼓励博主持续创作!


  • Ethereum/Polygon/Bsc/Arbitrum: 0xa8c00949fd7dD23b5Ec36A9181966c8C8436A015
  • Bitcoin: bc1qdvf0j0rntarvdal62n35etwmjzwk307w4jtyjz
  •    
  • 支付宝:

  • 发表评论

    邮箱地址不会被公开。 必填项已用*标注