【LEETCODE】77-Combinations [Python]
来源:互联网 发布:淘宝网div css布局实例 编辑:程序博客网 时间:2024/05/22 08:01
Given two integers n and k, return all possible combinations ofk 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],
]
题意:
给两个整数 n,k,返回 1 to n 中取 k 个数字的所有可能的组合
思路:
DFS
参考:
http://www.cnblogs.com/zuoyuan/p/3757165.html
Python
class Solution(object): def combine(self, n, k): """ :type n: int :type k: int :rtype: List[List[int]] """ ans=[] self.count=0 def dfs(start,nums): if self.count==k: ans.append(nums) return for i in range(start,n+1): self.count+=1 dfs(i+1,nums+[i]) self.count-=1 dfs(1,[]) return ans
0 0
- 【LEETCODE】77-Combinations [Python]
- LeetCode 77 Combinations (Python详解及实现)
- 【LeetCode with Python】 Combinations
- 【Leetcode】【python】Combinations
- LeetCode 77 Combinations
- [leetcode 77] Combinations
- Leetcode NO.77 Combinations
- [leetcode] 77 Combinations
- [LeetCode 77]Combinations
- leetcode || 77、Combinations
- leetcode-77 Combinations
- LeetCode-77 Combinations(组合)
- Combinations - LeetCode 77
- leetcode 77:Combinations
- LeetCode(77) Combinations
- Leetcode #77 Combinations
- [leetcode-77]Combinations(java)
- leetcode 77: Combinations
- 在list集合中的添加、修改、删除和遍历元素
- Windows Cython 安装
- Linux useradd 命令
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- unity3d中脚本生命周期(MonoBehaviour lifecycle)
- 【LEETCODE】77-Combinations [Python]
- oracle merge into 用法详解
- 以下是JavaScript容易犯错的九个陷阱。
- 机器学习实战第三章——决策树(源码解析)
- android 关闭弹出键盘
- Java语言实现的Hack语言汇编编译器——加法器部分
- hls流媒体:ts流格式介绍 已有 2028 次阅读2015-2-26 14:13 |个人分类:视频直播| 流媒体 1.ts简介 ts流最早应用于数字电视领域,其格式非常复杂包含的配置信息表
- 逻辑回归(logistic regression)
- Oracle 树操作(select…start with…connect by…prior)