All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0001_0100.s0096_unique_binary_search_trees.Solution Maven / Gradle / Ivy

There is a newer version: 1.37
Show newest version
package g0001_0100.s0096_unique_binary_search_trees;

// #Medium #Top_100_Liked_Questions #Dynamic_Programming #Math #Tree #Binary_Tree
// #Binary_Search_Tree #Dynamic_Programming_I_Day_11
// #2022_06_21_Time_0_ms_(100.00%)_Space_40.4_MB_(72.43%)

public class Solution {
    public int numTrees(int n) {
        long result = 1;
        for (int i = 0; i < n; i++) {
            result *= 2L * n - i;
            result /= i + 1;
        }
        result /= n + 1;
        return (int) result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy