摘要:
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.[解题思路]1.brute force枚举所有sub-matrix(O(N^2), N = m*n) ,检查每个子矩阵是不是都是1,如果是更新最大面积,检查子矩阵是否都是1需要花费O(N). 故总的时间为O(N^3) N = m*n可以过小数据,大数据直接TLE 1 public int maximalRectangle(char[][] matr 阅读全文
摘要:
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 / / \ ... 阅读全文
摘要:
Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="aadbbbaccc", return false.[解题思路]DPLet F(i, j) denote if s1 of length i and s2 of length j could form s3 of len 阅读全文