摘要: 题目:Determine whether an integer is a palindrome. Do this without extra space.解题思路:循环取得首位和末尾,然后比较。解题心得:关于整数的处理有几个 运算需要熟记:一个整数:%10 得个位 , %100 的后两位 就是个位和... 阅读全文
posted @ 2015-08-19 09:47 fengmang 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).Find the minimum element.Yo... 阅读全文
posted @ 2015-08-19 08:10 fengmang 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 题目:(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) 编辑