上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 20 下一页
摘要: Q: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.A: DP题。这道题hulu面试出过,当时sb了,想着用递归做,但是考虑一种极限情况 XXX ,XXX,XXXXXX. 如果递归的话,分支每次要走两个支路,复杂度是 阅读全文
posted @ 2013-09-24 15:55 summer_zhou 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Q:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs.For example, givens="aab",Return1since the palindrome partitioning["aa","b"]could be produced using 1 cut.A: 两个DP的结合: 阅读全文
posted @ 2013-09-23 22:19 summer_zhou 阅读(152) 评论(0) 推荐(0) 编辑
摘要: Q:Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region .For example,X X X XX O O XX X O XX O X XAfter running your function, the board should be:X X X XX X X XX X 阅读全文
posted @ 2013-09-22 23:00 summer_zhou 阅读(151) 评论(0) 推荐(1) 编辑
摘要: 回文partition一般有以下几种情况:1. 求所有的partition结果。这个一般用DFS来解。2. 最后结果是一个整数,比如Palindrome Partitioning II。这个用DP来解3. 最后求一个结果,比如最小切法。这个用DP+backtrack来解4. 最长回文子串问题1:求所有的回文partition结果,用简单的DFS就可以求出。 bool isPalin(string &s,int l,int r) { while(l> partition(string s) { // Start typing your C/C++ solu... 阅读全文
posted @ 2013-09-20 23:18 summer_zhou 阅读(197) 评论(0) 推荐(0) 编辑
摘要: Q:Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return6.A: 树的问题,第一个考虑就是递归解决。对于root为根节点的子树,maxPathSum的来源有以下几种情况:1. root左子树 2. root右子树 3. 路径穿过root:分为三种情况:来自左子树+root;来自右子树+root;左子树+roo... 阅读全文
posted @ 2013-09-20 20:17 summer_zhou 阅读(129) 评论(0) 推荐(0) 编辑
摘要: Q:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).A: 允许最多交易 阅读全文
posted @ 2013-09-20 16:45 summer_zhou 阅读(176) 评论(0) 推荐(0) 编辑
摘要: Q:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions a 阅读全文
posted @ 2013-09-19 23:50 summer_zhou 阅读(149) 评论(0) 推荐(0) 编辑
摘要: Q: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 阅读全文
posted @ 2013-09-19 23:20 summer_zhou 阅读(282) 评论(0) 推荐(0) 编辑
摘要: Q:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement must be in-place, do not allocate extra memory. 阅读全文
posted @ 2013-09-19 16:59 summer_zhou 阅读(262) 评论(0) 推荐(0) 编辑
摘要: Q:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.A: 用字符串模拟数字相乘。keyPoints:1.先把字符串转换成int数组,再对位相乘。2.将int数组转换成字符串。注意:这里字符串第0位表示的应是数字的高位,所以最后需要将字符串reverse一下 string multiply(string num1, string n... 阅读全文
posted @ 2013-09-19 14:55 summer_zhou 阅读(158) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 20 下一页