上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 43 下一页
摘要: Implement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function prototype should be:bool i 阅读全文
posted @ 2013-08-25 19:32 feiling 阅读(290) 评论(0) 推荐(0) 编辑
摘要: Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ofs1="great": great / \ gr eat / \ / \g r e at / \ a tTo scramble the string, we may choose any non-leaf no... 阅读全文
posted @ 2013-08-23 23:19 feiling 阅读(294) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its zigzag level order traversal as:[ [3], ... 阅读全文
posted @ 2013-08-23 22:10 feiling 阅读(245) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6[解题思路] 1 \ ... 阅读全文
posted @ 2013-08-23 21:14 feiling 阅读(1232) 评论(0) 推荐(1) 编辑
摘要: Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onlyO(k) extra space?[解题思路]从后往前计算,另外Trangle的index从0开始,故分配的数组大小为rowIndex + 1 1 public class Solution { 2 public ArrayList getRow(int rowIndex) { 3 ... 阅读全文
posted @ 2013-08-23 12:59 feiling 阅读(304) 评论(0) 推荐(0) 编辑
摘要: GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]][解题思路]第三行开始,每行除边界元素外,每个元素ai都是由ai-1 + ai构成 1 public class Solution { 2 public ArrayList> generate(int numRows) { 3 // Start typing your Ja... 阅读全文
posted @ 2013-08-23 11:18 feiling 阅读(435) 评论(0) 推荐(0) 编辑
摘要: Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.[解题思路]与上题类似Construct Binary Tree from Preorder and Inorder Traversal确定左右子树的序列,递归建立树,唯一不同在于后序遍历,根节点在最后一个元素 1 /** 2 * Definition for binary tree 3 * public class Tr.. 阅读全文
posted @ 2013-08-23 10:53 feiling 阅读(308) 评论(0) 推荐(0) 编辑
摘要: Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.[解题思路]由前序遍历知第一个节点是根节点,根据此节点值去中序遍历集合中找该root值所处位置,该位置之前的数属于左子树,之后的属于右子树,即找到左子树和右子树所处的子序列,接下来就可以用递归来完成递归的终止条件:preorder中仅有一个元素且preorder中的元素和inorder中元素相同 1 /** 2 * @auth. 阅读全文
posted @ 2013-08-23 10:33 feiling 阅读(447) 评论(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-08-22 23:38 feiling 阅读(262) 评论(0) 推荐(0) 编辑
摘要: Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) Insert a characterb) Delete a characterc) Replace a character[解题思路]这里用ed(s1, s2)来表示s1, s2之间的edit distanceba 阅读全文
posted @ 2013-08-21 16:03 feiling 阅读(597) 评论(0) 推荐(0) 编辑
上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 43 下一页