题目链接:https://leetcode.com/problems/binary-tree-inorder-traversal/(非递归实现)二叉树的中序遍历。 1 class Solution 2 { 3 public: 4 vector inorderTraversal(TreeNod...
分类:
其他好文 时间:
2015-04-05 23:29:30
阅读次数:
149
题目链接:https://leetcode.com/problems/unique-binary-search-trees/从最简单的情况开始考虑:n = 0 :只有“空树”这一种情况。f[0]= 1。n = 1 :只有“根节点”这一种情况。f[1]= 1。n = 2 :由于“根节点”必须存在,所以...
分类:
其他好文 时间:
2015-04-05 23:28:47
阅读次数:
171
题目链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/当 k ≥ prices.size()/ 2 时:题目等价于 k 无限大的情形。当 k < prices.size()/ 2 时:用dp[m][n+1]表示在[...
分类:
其他好文 时间:
2015-04-05 23:27:12
阅读次数:
161
题目链接:https://leetcode.com/problems/binary-tree-postorder-traversal/(非递归实现)二叉树的后序遍历。 1 class Solution 2 { 3 public: 4 vector postorderTraversal(Tre...
分类:
其他好文 时间:
2015-04-05 23:24:15
阅读次数:
160
题目链接:https://leetcode.com/problems/maximum-product-subarray/较麻烦的解法:先判断数组中有没有0,有的话可以转换为求"0之前"和"0之后"两部分的较大值。遍历,记录数组中负数的个数:偶数:由于数组中都是整数,最大值即这些值的乘积。奇数:有以下...
分类:
其他好文 时间:
2015-04-05 23:22:57
阅读次数:
164
题目链接:https://leetcode.com/problems/n-queens-ii/N皇后问题的位运算实现。 1 class Solution 2 { 3 public: 4 int totalNQueens(int n) 5 { 6 upperLimit ...
分类:
其他好文 时间:
2015-04-05 23:21:00
阅读次数:
167
题目链接:https://leetcode.com/problems/linked-list-cycle/判断一个链表中是否有环,可以设置两个指针,第一个每次前进一格,第二个每次前进两格。对于前进两格的指针,需要先判断前进一格时是否为 NULL :如果不判断是不是 NULL ,取两次 next 可能...
分类:
其他好文 时间:
2015-04-05 23:19:42
阅读次数:
179
题目链接:https://leetcode.com/problems/binary-tree-maximum-path-sum/题中要求 maxPathSum(TreeNode *root)函数返回二叉树中最大的"Path Sum"。而这个最大的"Path Sum"可以被分解为三部分之和:"左子树的...
分类:
其他好文 时间:
2015-04-05 23:11:44
阅读次数:
158
#安装驱动# pacman -S cups ghostscript gsfonts gutenprint#启动服务# systemctl start/enable org.cups.cupsd.service#驱动配置界面# http://localhost:631参考:https://wiki.a...
分类:
系统相关 时间:
2015-04-05 21:41:20
阅读次数:
350
2.1 用enum做数值计算下面两篇文章都介绍了模板元编程,enum是其最重要的基本工具 http://www.codeproject.com/Articles/3743/A-gentle-introduction-to-Template-Metaprogramming https://www10.informatik.uni-erlangen.de/~pflaum/pflaum/ProSemin...
分类:
编程语言 时间:
2015-04-05 17:31:44
阅读次数:
118