摘要:
原题地址从编号为0开始,不断递推到第k个如果用p[i][j]表示第i层,第j个数字,则有递推公式:p[i][j] = p[i-1][j-1] + p[i-1][j]因为只使用了相邻层,因此可以压缩状态空间代码: 1 vector getRow(int rowIndex) { 2 if... 阅读全文
posted @ 2015-02-02 15:20
李舜阳
阅读(113)
评论(0)
推荐(0)
摘要:
原题地址基本模拟题代码: 1 vector > generate(int numRows) { 2 vector > res; 3 4 if (numRows (1, 1)); 8 while (--numRows) { 9 ... 阅读全文
posted @ 2015-02-02 14:08
李舜阳
阅读(125)
评论(0)
推荐(0)
摘要:
原题地址基本模拟代码: 1 ListNode *removeNthFromEnd(ListNode *head, int n) { 2 ListNode *fast = head; 3 ListNode *slow = head; 4 ListNode... 阅读全文
posted @ 2015-02-02 14:01
李舜阳
阅读(105)
评论(0)
推荐(0)
摘要:
原题地址注意空树即使sum=0也不算代码: 1 bool solve(TreeNode *root, int sum) { 2 if (!root->left && !root->right) 3 return sum == root->val; 4 5 return (root-... 阅读全文
posted @ 2015-02-02 12:05
李舜阳
阅读(123)
评论(0)
推荐(0)
摘要:
原题地址基本二叉树遍历代码:1 int minDepth(TreeNode *root) {2 if (!root)3 return 0;4 5 int l = root->left ? minDepth(root->l... 阅读全文
posted @ 2015-02-02 11:47
李舜阳
阅读(101)
评论(0)
推荐(0)
摘要:
原题地址参考了这篇博文的想法代码: 1 int balancedp(TreeNode *root) { 2 if (!root) 3 return 0; 4 5 int l = balancedp(root->left); 6 int r = balancedp(root->r... 阅读全文
posted @ 2015-02-02 11:38
李舜阳
阅读(152)
评论(0)
推荐(0)
摘要:
原题地址二叉树层次遍历,最后把遍历结果翻转一下即可代码: 1 vector > levelOrderBottom(TreeNode *root) { 2 vector > res; 3 queue layer; 4 5 layer.p... 阅读全文
posted @ 2015-02-02 11:16
李舜阳
阅读(204)
评论(0)
推荐(0)
摘要:
原题地址二叉树的遍历代码:1 int maxDepth(TreeNode *root) {2 if (!root)3 return 0;4 return max(maxDepth(root->left), maxDepth(root->righ... 阅读全文
posted @ 2015-02-02 11:11
李舜阳
阅读(142)
评论(0)
推荐(0)
摘要:
原题地址二叉树的层次遍历代码: 1 vector > levelOrder(TreeNode *root) { 2 vector > res; 3 queue layer; 4 5 layer.push(root); 6 ... 阅读全文
posted @ 2015-02-02 11:09
李舜阳
阅读(140)
评论(0)
推荐(0)
摘要:
原题地址递归比较左儿子和右儿子是否对称,左儿子的左儿子跟右儿子的右儿子比,左儿子的右儿子跟右儿子的左儿子比!打完这一串文字突然发现"儿"字怎么这么奇怪!代码: 1 bool mirrorp(TreeNode *a, TreeNode *b) { 2 if (a && b) 3 retur... 阅读全文
posted @ 2015-02-02 11:04
李舜阳
阅读(202)
评论(0)
推荐(0)

浙公网安备 33010602011771号