摘要: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 public static List<BSTNode> UniqueBinarySearchTreeII(int n) 2 { 3 return UniqueBinarySearchT... 阅读全文
posted @ 2012-10-22 23:56 ETCOW 阅读(343) 评论(0) 推荐(0) 编辑
摘要: Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's.1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \2 1 2 3 1 public static int UniqueBinarySearchTrees(int n) 2 ... 阅读全文
posted @ 2012-10-22 23:20 ETCOW 阅读(283) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are 阅读全文
posted @ 2012-10-22 22:48 ETCOW 阅读(1923) 评论(0) 推荐(0) 编辑
摘要: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. 1 public static int TrappingRainWater(int[] A) 2 { 3 if (A.Length ... 阅读全文
posted @ 2012-10-22 22:21 ETCOW 阅读(240) 评论(0) 推荐(0) 编辑
摘要: Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each 阅读全文
posted @ 2012-10-22 21:30 ETCOW 阅读(314) 评论(0) 推荐(0) 编辑