博客
关于我
4 组合
阅读量:493 次
发布时间:2019-03-07

本文共 534 字,大约阅读时间需要 1 分钟。

77. 组合给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合。示例:输入: n = 4, k = 2输出:[  [2,4],  [3,4],  [2,3],  [1,2],  [1,3],  [1,4],]通过次数161,020提交次数209,874
class Solution {       List
son=new ArrayList
(); List
> parent = new ArrayList
>(); public List
> combine(int n, int k) { dfs(1,n,k); return parent; } public void dfs(int cur,int n,int k){ if(cur==n+1){ if(son.size()==k){ parent.add(new ArrayList(son)); } return; } son.add(cur); dfs(cur+1,n,k); son.remove(son.size()-1); dfs(cur+1,n,k); }}

转载地址:http://uzzcz.baihongyu.com/

你可能感兴趣的文章
Node中自启动工具supervisor的使用
查看>>
Node入门之创建第一个HelloNode
查看>>
node全局对象 文件系统
查看>>
Node出错导致运行崩溃的解决方案
查看>>
Node响应中文时解决乱码问题
查看>>
node基础(二)_模块以及处理乱码问题
查看>>
node安装卸载linux,Linux运维知识之linux 卸载安装node npm
查看>>
node安装及配置之windows版
查看>>
Node实现小爬虫
查看>>
Node提示:error code Z_BUF_ERROR,error error -5,error zlib:unexpected end of file
查看>>
Node提示:npm does not support Node.js v12.16.3
查看>>
Node搭建静态资源服务器时后缀名与响应头映射关系的Json文件
查看>>
Node服务在断开SSH后停止运行解决方案(创建守护进程)
查看>>
node模块化
查看>>
node模块的本质
查看>>
node环境下使用import引入外部文件出错
查看>>
node环境:Error listen EADDRINUSE :::3000
查看>>
Node的Web应用框架Express的简介与搭建HelloWorld
查看>>
Node第一天
查看>>
node编译程序内存溢出
查看>>