上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 43 下一页
摘要: Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.255.11.135", "255.255.111.35"]. (Order does not matter)[解题思路]DFS + Backtracking给定的字符串分成4段,每段都0 剩余段数*32.剩余位数 restoreIpAddr 阅读全文
posted @ 2013-09-04 19:50 feiling 阅读(734) 评论(1) 推荐(0) 编辑
摘要: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S="ADOBECODEBANC"T="ABC"Minimum window is"BANC".Note:If there is no such window in S that covers all characters in T, return the emtpy 阅读全文
posted @ 2013-09-04 17:01 feiling 阅读(848) 评论(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.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 阅读全文
posted @ 2013-09-02 17:23 feiling 阅读(341) 评论(0) 推荐(0) 编辑
摘要: 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-02 11:31 feiling 阅读(757) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2013-09-02 10:50 feiling 阅读(576) 评论(0) 推荐(0) 编辑
摘要: Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the previous row.For example,Consider the following matrix:[ [1, 3, ... 阅读全文
posted @ 2013-08-31 23:03 feiling 阅读(178) 评论(0) 推荐(0) 编辑
摘要: Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.For example,Givenboard=[ [&q 阅读全文
posted @ 2013-08-30 23:16 feiling 阅读(460) 评论(1) 推荐(0) 编辑
摘要: Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array A =[1,1,1,2,2,3],Your function should return length =5, and A is now[1,1,2,2,3].[解题思路]双指针问题,还是使用count来保存结果数组的大小与Remove Duplicates from Sorted Array唯一区别在添加start, end标识duplicates区间如果当 阅读全文
posted @ 2013-08-30 14:57 feiling 阅读(199) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.For example,Given input array A =[1,1,2],Your function should return length =2, and A is 阅读全文
posted @ 2013-08-30 12:57 feiling 阅读(159) 评论(0) 推荐(0) 编辑
摘要: Persistent environment variablesSo far we've only discussed ways set an environment variable value temporarily until the shell session in which it was set is closed. One may wonder if there is a way to somehow permanently set an environment variable to a certain value.Note:The shell config files 阅读全文
posted @ 2013-08-26 22:45 feiling 阅读(314) 评论(0) 推荐(0) 编辑
上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 43 下一页