LeetCode OJ combine 3
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的更多相关文章
- LeetCode OJ 题解
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...
- 【LeetCode OJ】Interleaving String
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...
- 【LeetCode OJ】Reverse Words in a String
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...
- LeetCode OJ学习
一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...
- 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 ...
- 备份LeetCode OJ自己编写的代码
常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Web Scraper使用
{ "selectors": [{ "parentSelectors": ["_root"], "type": &quo ...
- ios下点击穿透focus获取问题
在ios下的浏览器中当点击当前页的一个按钮,用window.location.href进行跳转时,如果下一个页面里这点击按钮的位置是一个textarea或者text等那么他会触发focus事件,会出现 ...
- hibernate、easyui、struts2整合
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Epidemic in Monstropolis
Epidemic in Monstropolis 题目链接:http://codeforces.com/contest/733/problem/C 贪心 新序列的m个数肯定是由原序列的连续的m个子序列 ...
- JDK根目录介绍
/bin 存放可执行程序(编译器javac.exe 运行器java.exe 文档生成器javadoc.exe等 ). /db 小型数据库文件. /jre JRE. /include 形成jdk的c. ...
- nodejs 中es5 模块的几种写法
1. module.exports.func = function(){} module.exports.field = ''; 第一种是逐个对api 和字段导出. 2. module.export ...
- [SOJ]统计数字
Description 某次科研调查时得到了n个自然数,每个数均不超过1500000000(1.5*10^9).已知不相同的数不超过10000个,现在需要统计这些自然数各自出现的次数,并按照自然数从小 ...
- Lua: 给 Redis 用户的入门指导
转自:http://www.oschina.net/translate/intro-to-lua-for-redis-programmers 可能你已经听说过Redis 中嵌入了脚本语言,但是你还没有 ...
- 【实验室笔记】C#以本地时间创建txt文件
前段时间做的一个小项目,要求上位机在打开时候,以打开软件的系统时间的建立一个txt文件来存储下位机发送来的数据. 在第一版上位机上,取名的办法太弱了,先是读取系统时间,然后截取字符串,太笨拙.昨天,查 ...
- PHP mktime函数获取今天的开始和结束时间戳
php 获取今日.昨日.上周.本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime(). mktime函数用法如下:mktime(hour,minute,second,m ...