Skip to content

Commit

Permalink
how many k you can choose from n
Browse files Browse the repository at this point in the history
  • Loading branch information
Atousa committed Apr 21, 2021
1 parent 8bcef49 commit bb47223
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Recursion/NChooseK.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class NChooseK {
//paskal triangle
public static int nChooseK(int n , int k) {
if(n <= 1 || k == 0 || k == n) return 1; // base cases bases on Pascal's triangle
return nChooseK(n-1,k ) + nChooseK(n-1,k-1 );
}

public static void main(String[] args) {
System.out.println(nChooseK(3,2));
}
}

0 comments on commit bb47223

Please sign in to comment.