上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 20 下一页
摘要: 回溯 vector visited; int m,n; bool exist(vector > &board, string word) { // Start typing your C/C++ solution below // DO NOT write int main() function if(word.empty()) return true; m = board.size(); n = board[0].size(); visited.clear(); ... 阅读全文
posted @ 2013-10-05 16:12 summer_zhou 阅读(183) 评论(0) 推荐(0) 编辑
摘要: DP vector grayCode(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function vector res; if(n=0;j--) res.push_back(added+res[j]); cnt *= 2; } return res; } 阅读全文
posted @ 2013-10-05 15:27 summer_zhou 阅读(134) 评论(0) 推荐(0) 编辑
摘要: C(n,k) 回溯 vector > combine(int n, int k) { // Note: The Solution object is instantiated only once and is reused by each test case. vector> res; vector path; construct(1,n,k,path,res); return res; } bool construct(int pos,int n,int k,vector& pat... 阅读全文
posted @ 2013-10-05 15:09 summer_zhou 阅读(198) 评论(0) 推荐(0) 编辑
摘要: int minDistance(string word1, string word2) { // Note: The Solution object is instantiated only once and is reused by each test case. int m = word1.size(); int n = word2.size(); vector> dp(m+1,vector(n+1,0)); int i,j; for(j=0;j<=n;j++) ... 阅读全文
posted @ 2013-10-05 14:11 summer_zhou 阅读(152) 评论(0) 推荐(0) 编辑
摘要: Q:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?A: 如果交换了,inorder seq中的逆序对可能是1对(父子节点交换),或者2对。 void recoverTree(TreeNode *root)... 阅读全文
posted @ 2013-10-05 13:11 summer_zhou 阅读(149) 评论(0) 推荐(0) 编辑
摘要: //DP bool isInterleave(string s1, string s2, string s3) { // Note: The Solution object is instantiated only once and is reused by each test case. //DP if(s1.empty()&&s2.empty()&&s3.empty()) return true; int m = s1.size(); int n = s2.size(); i... 阅读全文
posted @ 2013-10-05 12:22 summer_zhou 阅读(150) 评论(0) 推荐(0) 编辑
摘要: vector > zigzagLevelOrder(TreeNode *root) { // Note: The Solution object is instantiated only once and is reused by each test case. vector> res; if(!root) return res; int cnt=1; int tmp; vector levelres; bool bForward = true; que... 阅读全文
posted @ 2013-10-05 10:57 summer_zhou 阅读(178) 评论(0) 推荐(0) 编辑
摘要: bool isSymmetric(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function if(!root) return true; return helper(root->left,root->right); } bool helper(TreeNode* root1, TreeNode* root2) { if(!root1&&!... 阅读全文
posted @ 2013-10-05 09:43 summer_zhou 阅读(163) 评论(0) 推荐(0) 编辑
摘要: bottom up. TreeNode *sortedListToBST(ListNode *head) { // Note: The Solution object is instantiated only once and is reused by each test case. //1. getLength if(!head) return NULL; int len = 0; ListNode* cur = head; while(cur) { ... 阅读全文
posted @ 2013-10-05 09:30 summer_zhou 阅读(166) 评论(0) 推荐(0) 编辑
摘要: bool isBalanced(TreeNode *root) { // Note: The Solution object is instantiated only once and is reused by each test case. int depth; return helper(root,depth); } bool helper(TreeNode* root,int& depth) { if(!root) { depth = 0; ... 阅读全文
posted @ 2013-10-04 23:00 summer_zhou 阅读(106) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 20 下一页