Skip to content

Instantly share code, notes, and snippets.

@xynophon
Created January 27, 2015 07:03
Show Gist options
  • Select an option

  • Save xynophon/0e00df420d34af154b61 to your computer and use it in GitHub Desktop.

Select an option

Save xynophon/0e00df420d34af154b61 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
/**
* Created by xynophon on 15.1.27.
*/
public class Unique_Binary_Search_Trees {
public int solution(int n){
int dbnum = 2*n;
long result = 1;
int cnt = 0;
while(dbnum > 0){
cnt++;
if(cnt < n)
result *= dbnum--;
else if (cnt == n)
dbnum--;
else
result /= dbnum--;
}
return (int)result;
}
public static void main(String args[]){
Unique_Binary_Search_Trees ubst = new Unique_Binary_Search_Trees();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(ubst.solution(n));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment