摘要: 与上一题相同。 class Solution { public: int calLen(ListNode *node) { int len = 0; while(node) { len++; node = node->next; } return len; } void createTree(ListNode *node, int start, int end, TreeNode *&tmpRoot) { ... 阅读全文
posted @ 2013-04-15 03:22 tanghulu321 阅读(98) 评论(0) 推荐(0) 编辑
摘要: 一开始用的第一种解法,但是大测试内存超了,所以不能迭代的时候不能每次返回一个TreeNode,而是需要建立一个引用,每一次修改引用可以节省空间。时间复杂度来说都是一样的。class Solution {public: TreeNode *build(vector<int> num, int start, int end){ if (start > end) return NULL; int mid = (start + end) / 2; TreeNode *tmpRoot = new TreeNode(num[m... 阅读全文
posted @ 2013-04-15 03:05 tanghulu321 阅读(127) 评论(0) 推荐(0) 编辑