01 2015 档案

摘要:题目:(Backtrancing)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 ce... 阅读全文
posted @ 2015-01-08 22:48 fengmang 阅读(163) 评论(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./** * Defini... 阅读全文
posted @ 2015-01-06 03:00 fengmang 阅读(115) 评论(0) 推荐(0) 编辑
摘要:题目(Tree DFS)Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The... 阅读全文
posted @ 2015-01-06 02:37 fengmang 阅读(142) 评论(0) 推荐(0) 编辑
摘要:题目:(Tree ,DFS)Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using ... 阅读全文
posted @ 2015-01-06 01:39 fengmang 阅读(124) 评论(0) 推荐(0) 编辑
摘要:题目:(DP)Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return al... 阅读全文
posted @ 2015-01-06 00:09 fengmang 阅读(186) 评论(0) 推荐(0) 编辑
摘要:套路:一般有两个string的时候 都建二维的数组来存。int[][] dp =new int[len+1][len+1];初始情况已设立dp[0][0] = 1;递归循环for()dp[i][j] = dp [i-1][j];交答案dp[len][len] 阅读全文
posted @ 2015-01-05 22:16 fengmang 阅读(126) 评论(0) 推荐(0) 编辑
摘要:题目:(Backtrancing)Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a soluti... 阅读全文
posted @ 2015-01-03 03:28 fengmang 阅读(68) 评论(0) 推荐(0) 编辑
摘要:主线是reshelper(res);dfs();helper(res,num,curr, index, resultOne, visited..){ if(curr==num) 1 res.add(resultOne); 2 res.add(new resultOne); e... 阅读全文
posted @ 2015-01-03 01:19 fengmang 阅读(144) 评论(0) 推荐(0) 编辑
摘要:题目:(DP)Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from t... 阅读全文
posted @ 2015-01-02 10:13 fengmang 阅读(149) 评论(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 representat... 阅读全文
posted @ 2015-01-02 04:06 fengmang 阅读(117) 评论(0) 推荐(0) 编辑
摘要:题目:(DP)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... 阅读全文
posted @ 2015-01-02 03:43 fengmang 阅读(176) 评论(0) 推荐(0) 编辑
摘要:题目:(DP, Backtracing)Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Ret... 阅读全文
posted @ 2015-01-02 01:53 fengmang 阅读(255) 评论(0) 推荐(0) 编辑
摘要:BFS有固定的套路 类似下面这个形式ArrayList queue = new ArrayList();queue.add(root);while(!queue.isEmpty()){ String temp = queue.poll(); for(neigbor : t... 阅读全文
posted @ 2015-01-01 11:07 fengmang 阅读(97) 评论(0) 推荐(0) 编辑
摘要:题目:Given two words (startandend), and a dictionary, find all shortest transformation sequence(s) fromstarttoend, such that:Only one letter can be chan... 阅读全文
posted @ 2015-01-01 10:44 fengmang 阅读(179) 评论(0) 推荐(0) 编辑
摘要:几个套路第一 fast slow 找中点,找位数。第二 reverse{ ListNode last = prev.next; ListNode curr = last.next; while(curr!=null) { last.next = curr.next; ... 阅读全文
posted @ 2015-01-01 07:02 fengmang 阅读(106) 评论(0) 推荐(0) 编辑
摘要:题目:(Tree ,Stack)Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3... 阅读全文
posted @ 2015-01-01 06:51 fengmang 阅读(101) 评论(0) 推荐(0) 编辑
摘要:题目:(Stack)Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in ... 阅读全文
posted @ 2015-01-01 04:39 fengmang 阅读(125) 评论(0) 推荐(0) 编辑
摘要:题目:(LinkedList)Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3... 阅读全文
posted @ 2015-01-01 01:01 fengmang 阅读(79) 评论(0) 推荐(0) 编辑