GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/src/UniqueBinarySearchTrees.java at master · LeBW/leetcode Expand file tree/ Copy pathUniqueBinarySearchTrees.javaMore file actions 25 lines (24 loc) · 653 Bytes / Copy pathUniqueBinarySearchTrees.javaFile metadata and controls25 lines (24 loc) · 653 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 /** * 96. Unique Binary Search Trees * 动态规划 * @author LBW */ public class UniqueBinarySearchTrees { public int numTrees(int n) { int[] dp = new int[n+1]; dp[0] = 1; dp[1] = 1; for (int i = 2; i <= n; i++) { // compute dp[i] dp[i] = 0; for (int j = 0; j < i; j++) { dp[i] += dp[j] * dp[i-j-1]; } } return dp[n]; } public static void main(String[] args) { UniqueBinarySearchTrees uniqueBinarySearchTrees = new UniqueBinarySearchTrees(); System.out.println(uniqueBinarySearchTrees.numTrees(8)); } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |