Skip to content

Merge latest updates #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
bd11ddf
KthSort
yuzhangcmu Sep 23, 2014
841e167
add the demos
yuzhangcmu Sep 23, 2014
dabfdb7
min cut
yuzhangcmu Sep 25, 2014
762dcad
Create README.md
yuzhangcmu Sep 25, 2014
ce3384e
Update README.md
yuzhangcmu Sep 25, 2014
078baa7
modify the directors
yuzhangcmu Sep 26, 2014
ab453fc
move the folder.
yuzhangcmu Sep 26, 2014
af5edeb
modify the tree Demo
yuzhangcmu Sep 26, 2014
52407ba
The LCA problem.
yuzhangcmu Sep 26, 2014
7c9819f
add some comments.
yuzhangcmu Sep 26, 2014
bb3eb2b
Arrange the code.
yuzhangcmu Sep 27, 2014
fa314c2
merge Sort
yuzhangcmu Sep 28, 2014
37c4105
merge
yuzhangcmu Oct 2, 2014
b0e4e32
Five Chessman
yuzhangcmu Oct 2, 2014
441dba7
FiveChessman
yuzhangcmu Oct 2, 2014
2eec824
notes
yuzhangcmu Oct 2, 2014
1551e7f
the largest Common subtree
yuzhangcmu Oct 2, 2014
61e79b2
the largest common
yuzhangcmu Oct 2, 2014
ff798ae
largestCommon
yuzhangcmu Oct 2, 2014
718698d
TestPermutation
yuzhangcmu Oct 5, 2014
7d60ff4
isCompleteBinaryTree
yuzhangcmu Oct 5, 2014
c73a8a7
NextPermutation
yuzhangcmu Oct 5, 2014
8c9f0e8
permutation sequence
yuzhangcmu Oct 5, 2014
b8c8f5f
Fibonacci
yuzhangcmu Oct 5, 2014
92f4168
add new file
Oct 7, 2014
f928b91
add code.
Oct 7, 2014
b6817a6
Recover Binary Search Tree
yuzhangcmu Oct 8, 2014
a758230
isValidBST
yuzhangcmu Oct 8, 2014
c04d009
in order
yuzhangcmu Oct 8, 2014
3292319
tree
yuzhangcmu Oct 8, 2014
8f28a48
tree
yuzhangcmu Oct 8, 2014
2d0cf85
minDepth
yuzhangcmu Oct 8, 2014
dc15508
min
yuzhangcmu Oct 8, 2014
de48d99
facebook
yuzhangcmu Oct 8, 2014
72f914d
Unique BSTs
yuzhangcmu Oct 9, 2014
d92fcd1
tree2
yuzhangcmu Oct 9, 2014
632666f
merge Sort
yuzhangcmu Oct 9, 2014
d1c27bd
merge
yuzhangcmu Oct 9, 2014
ec77e43
remove duplicate
yuzhangcmu Oct 9, 2014
127db30
remove duplicates2
yuzhangcmu Oct 9, 2014
63dd8d0
array
yuzhangcmu Oct 9, 2014
23f07e3
search
yuzhangcmu Oct 9, 2014
bd02708
maxSubArray
yuzhangcmu Oct 9, 2014
88a4d50
the merge
yuzhangcmu Oct 9, 2014
0ccff33
strstr
yuzhangcmu Oct 10, 2014
096b743
list
yuzhangcmu Oct 10, 2014
d955d59
divide
yuzhangcmu Oct 10, 2014
218d63f
pow
yuzhangcmu Oct 10, 2014
4f99b2d
pow
yuzhangcmu Oct 10, 2014
7564463
list
yuzhangcmu Oct 10, 2014
1ddacc5
sort
yuzhangcmu Oct 10, 2014
d5573fc
reorder list
yuzhangcmu Oct 10, 2014
c144ac6
random
yuzhangcmu Oct 10, 2014
2a37fec
reverse2
yuzhangcmu Oct 10, 2014
150f920
tree
yuzhangcmu Oct 10, 2014
82143ad
name
yuzhangcmu Oct 10, 2014
f08140a
lett
yuzhangcmu Oct 11, 2014
42796c9
list
yuzhangcmu Oct 11, 2014
d6d1308
list
yuzhangcmu Oct 11, 2014
0060c07
rotate
yuzhangcmu Oct 11, 2014
72e5ddf
list
yuzhangcmu Oct 11, 2014
cfdbfe8
remove
yuzhangcmu Oct 11, 2014
732d38a
list
yuzhangcmu Oct 11, 2014
53f429f
tree
yuzhangcmu Oct 11, 2014
1693ac2
candy
yuzhangcmu Oct 11, 2014
7a80b46
combine
yuzhangcmu Oct 11, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
combine
  • Loading branch information
yuzhangcmu committed Oct 11, 2014
commit 7a80b4624546070af1d87069f6fa3805dda7bb58
41 changes: 41 additions & 0 deletions combination/Combinations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package Algorithms.combination;

import java.util.ArrayList;
import java.util.List;

public class Combinations {
public List<List<Integer>> combine(int n, int k) {
List<List<Integer>> ret = new ArrayList<List<Integer>>();

if (n == 0 || k == 0) {
return ret;
}

List<Integer> path = new ArrayList<Integer>();

combine(n, k, path, ret, 1);

return ret;
}

// index means the position which I can choose from.
// for example: when n = 4,
// 1, 2, 3, 4, and index = 1, means now I can choose a number from 1 - 4
//
public void combine(int n, int k, List<Integer> path, List<List<Integer>> ret, int index) {
if (0 == k) {
ret.add(new ArrayList<Integer>(path));
return;
}

// 注意这里的终止条件.
// For example: N = 4的时候,K = 2的时候,
// 这里还有2个可以取值,那么 1, 2, 3, 4中index最多可以从3取值,也就是4-2+1.
// 就是 n - k + 1
for (int i = index; i <= n - k + 1; i++) {
path.add(i);
combine(n, k - 1, path, ret, i + 1);
path.remove(path.size() - 1);
}
}
}