摘要: 解法一:递归1 int Fib(int n)2 {3 if (n m00 = m.m00; 8 this->m01 = m.m01; 9 this->m10 = m.m10;10 this->m11 = m.m11;11 ret... 阅读全文
posted @ 2015-07-07 10:45 QingLiXueShi 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 1 string addBinary(string a, string b) 2 { 3 int alen = a.size(); 4 int blen = b.size(); 5 if (alen == 0) 6 return b; 7 else ... 阅读全文
posted @ 2015-07-07 09:17 QingLiXueShi 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 解法一:Brute-force 1 int strStr(string haystack, string needle) 2 { 3 int m = haystack.size(); 4 int n = needle.size(); 5 if (!n) 6 ... 阅读全文
posted @ 2015-07-06 16:04 QingLiXueShi 阅读(504) 评论(0) 推荐(0) 编辑
摘要: 1 void merge(vector& nums1, int m, vector& nums2, int n) 2 { 3 int i = m - 1; 4 int j = n - 1; 5 int k = m + n - 1; 6 while (i >=0 &&... 阅读全文
posted @ 2015-07-06 14:57 QingLiXueShi 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 1 vector summaryRanges(vector& nums) 2 { 3 int nums_len = nums.size(); 4 vector res; 5 if (nums_len == 0) 6 return res; 7 8 ... 阅读全文
posted @ 2015-07-06 14:19 QingLiXueShi 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 1 bool isPowerOfTwo(int n)2 {3 return n > 0 && !(n & (n - 1));4 } 阅读全文
posted @ 2015-07-06 11:07 QingLiXueShi 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 解法一:递归 1 bool isSameTree(TreeNode* p, TreeNode* q) 2 { 3 if (p == NULL && q == NULL) 4 return true; 5 if ((p == NULL && q != NULL) || ... 阅读全文
posted @ 2015-07-05 19:27 QingLiXueShi 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 解法一:递归1 int maxDepth(TreeNode* root)2 {3 if (root == NULL)4 return 0;5 6 int max_left_Depth = maxDepth(root->left);7 int max_right... 阅读全文
posted @ 2015-07-05 17:18 QingLiXueShi 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 解法一:From top to bottom 1 int treeHeight(TreeNode *T) 2 { 3 if (T == NULL) 4 return 0; 5 6 return max(treeHeight(T->left), treeHei... 阅读全文
posted @ 2015-07-05 17:03 QingLiXueShi 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 解法一:递归int minDepth(TreeNode* root) { if (root == NULL) return 0; if (root->left == NULL) { return minDepth(root->right) + 1; } ... 阅读全文
posted @ 2015-07-04 22:35 QingLiXueShi 阅读(164) 评论(0) 推荐(0) 编辑