2013年9月26日

Maximal Rectangle

摘要: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.看到2D,首先想到的就是那个二维矩阵中找最大子矩阵。同样也是可以降级到一维:给一个array,里面有1 和 0, 找联续1的最大长度。这个问题很好解决,即function findMax。然后再递归到二维即可。方法是先把bot定为最底层,然后把top从bot往上移,如果竖向看全1,则将抽象这个矩形的数组本位设为1,否则为0。然后找最大长度,乘上其放 阅读全文

posted @ 2013-09-26 13:45 Step-BY-Step 阅读(295) 评论(0) 推荐(0) 编辑

Partition List

摘要: 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-26 12:09 Step-BY-Step 阅读(259) 评论(0) 推荐(0) 编辑

Multiply Strings

摘要: Given two numbers represented as strings, returnmultiplication of thenumbers as a string.Note: The numbers can be arbitrarily large and are non-negati... 阅读全文

posted @ 2013-09-26 07:36 Step-BY-Step 阅读(212) 评论(0) 推荐(0) 编辑

Gray Code

摘要: The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, givenn= 2, return[0,1,3,2]. Its gray code s 阅读全文

posted @ 2013-09-26 06:58 Step-BY-Step 阅读(251) 评论(0) 推荐(0) 编辑

Decode Ways

摘要: A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded message"12", it cou 阅读全文

posted @ 2013-09-26 06:52 Step-BY-Step 阅读(187) 评论(0) 推荐(0) 编辑

Unique Binary Search Trees II

摘要: 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-26 02:44 Step-BY-Step 阅读(194) 评论(0) 推荐(0) 编辑

Unique Binary Search Trees

摘要: 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-26 02:35 Step-BY-Step 阅读(205) 评论(0) 推荐(0) 编辑

导航