摘要: Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ ... 阅读全文
posted @ 2013-09-21 11:34 LEDYC 阅读(194) 评论(0) 推荐(0)
摘要: Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 ... 阅读全文
posted @ 2013-09-21 11:29 LEDYC 阅读(135) 评论(0) 推荐(0)
摘要: Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note:Recursive solution is trivial, could you do it iteratively?confused what"{1,#,2,3}"means?> read more on how binary tree is serialized on OJ.---ino 阅读全文
posted @ 2013-09-21 11:17 LEDYC 阅读(138) 评论(0) 推荐(0)
摘要: Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.Note:Givenm,nsatisfy the following condition:1 ?m?n? length of list.---/** * Definition for singly-linked list. * public c 阅读全文
posted @ 2013-09-21 01:18 LEDYC 阅读(132) 评论(0) 推荐(0)
摘要: Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,IfS=[1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []]---public class... 阅读全文
posted @ 2013-09-21 01:06 LEDYC 阅读(167) 评论(0) 推荐(0)
摘要: Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B aremandnrespectively.---public class Solution { public void merge(int A[], int m, int B[], int ... 阅读全文
posted @ 2013-09-20 08:19 LEDYC 阅读(119) 评论(0) 推荐(0)
摘要: Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each of the two partitions.For example,Given1->4->3->2->5->2andx= 3,return1->2->2->4->3- 阅读全文
posted @ 2013-09-20 04:16 LEDYC 阅读(165) 评论(0) 推荐(0)
摘要: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.---1. O(n^3)2. 很想84, largest rectangle in histogra,每一行存以当前行为底的柱状图, 求最大矩形面积。O(N^2)---10/01 YC versionpublic class Solution { public int maximalRectangle(char[][] matrix) { ... 阅读全文
posted @ 2013-09-20 04:10 LEDYC 阅读(361) 评论(0) 推荐(0)
摘要: Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each bar is 1, given height =[2,1,5,6,2,3].The largest rectangle is shown in the shaded area, which has ar 阅读全文
posted @ 2013-09-20 03:15 LEDYC 阅读(237) 评论(0) 推荐(0)
摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3.---10/01 YC version:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next 阅读全文
posted @ 2013-09-16 10:35 LEDYC 阅读(121) 评论(0) 推荐(0)