public class Solution {
public List<List<Integer>> combinationSum3(int k, int n) {
return combination(k, n, 1);
} public List<List<Integer>> combination(int k, int target, int start) {
List<List<Integer>> list = new ArrayList<>();
if(k <= 0) return list; for(int i = start; i <= 10-k; i++){
if(i < target){
List<List<Integer>> tlist = combination(k, target - i, i+1);
if(tlist.size() > 0){
for(List<Integer> alist : tlist){
alist.add(0, i);
}
list.addAll(tlist);
}
}
else if(i == target){
List<Integer> tlist = new LinkedList<>();
tlist.add(target);
list.add(tlist);
}
else break;
}
return list;
}
}

LeetCode OJ combine 3的更多相关文章

  1. LeetCode OJ 题解

    博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...

  2. 【LeetCode OJ】Interleaving String

    Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...

  3. 【LeetCode OJ】Reverse Words in a String

    Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...

  4. LeetCode OJ学习

    一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...

  5. LeetCode OJ 297. Serialize and Deserialize Binary Tree

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  6. 备份LeetCode OJ自己编写的代码

    常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...

  7. LeetCode OJ 之 Maximal Square (最大的正方形)

    题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...

  8. LeetCode OJ:Integer to Roman(转换整数到罗马字符)

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  9. LeetCode OJ:Serialize and Deserialize Binary Tree(对树序列化以及解序列化)

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

随机推荐

  1. 记JavaScript的入门学习(二)

    2016年11月25号,利用上午时间学习了JavaScript的数据类型和变量,下午就该去图书馆泡书了. 看完变量的本章节,发现我可能不能一天结束,那我就利用上午和晚上九点回来的时间完成吧.把心态调整 ...

  2. 定位(position)

    position :属性规定元素的定位类型 语法: position : static | absolute | fixed | relative JavaScript语法:object.style. ...

  3. 必须掌握的Linux命令

    章节简述: 本章节讲述系统内核.Bash解释器的关系与作用,教给读者如何正确的执行Linux命令以及常见排错方法. 经验丰富的运维人员可以恰当的组合命令与参数,使Linux字符命令更加的灵活且相对减少 ...

  4. FormsCookieName保存登录用户名的使用

    一,写一个类来实现 using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...

  5. cp执行命令,如何直接覆盖不提示

    参数说明 -i, --interactive prompt before overwrite (overrides a previous -n option)   #文件存在是,交互式提示是否覆盖 - ...

  6. 【转】Jmeter(二)-使用代理录制脚本

    Jmeter脚本是以JMX格式为主 Jmeter也是支持录制的,支持第三方录制方式和代理录制方式. 1.第三方录制主要是通过badboy来录制,录制后另存为jmx格式即可. 2.Jmeter也有自己的 ...

  7. Django ORM操作

    ORM 常用操作进阶操作 #!/usr/bin/env python #_*_ coding:utf8 _*_ from __future__ import unicode_literals from ...

  8. mybatis的decimal精度缺失

    在mybatis里面用decimal确实方便,但是经过测试发现decimal默认只有一位小数,所以也不能滥用,如果是double类型的话还是要使用double

  9. mysql加密和解密

    MySQL 4.1版本之前是MySQL323加密,MySQL 4.1和之后的版本都是MySQLSHA1加密, (1)以MySQL323方式加密 select  old_password('111111 ...

  10. 折腾一天,终于配置好了,ssl证书,启用了https,用的阿里云ECS服务器

    阿里云ECS服务器配置了ssl证书, httpd-ssl.conf  的配置很重要,网站目录一定要设置正确. 阿里云的虚拟空间,弹性Web,目前好像还不支持ssl证书. 最后要网站强制https,下面 ...