会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Ry_Chen
博客园
首页
新随笔
联系
订阅
管理
上一页
1
2
3
4
5
6
7
8
9
10
···
16
下一页
2016年3月9日
[LeetCode]题解(python):106-Construct Binary Tree from Inorder and Postorder Traversal
摘要: 题目来源: https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ 题意分析: 给出一颗二叉树的中序遍历和后续遍历,还原这个树。 题目思路: 这题和上一题类似,用递归的思想,先
阅读全文
posted @ 2016-03-09 15:02 Ry_Chen
阅读(458)
评论(0)
推荐(0)
2016年3月7日
[LeetCode]题解(python):105-Construct Binary Tree from Preorder and Inorder Traversal
摘要: 题目来源: https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ 题意分析: 根据二叉树的中序和前序遍历结果,反推这个树,假设只有一个这样的树。 题目思路: 前序遍历的第一个树
阅读全文
posted @ 2016-03-07 18:44 Ry_Chen
阅读(665)
评论(0)
推荐(0)
[LeetCode]题解(python):104-Maximum Depth of Binary Tree
摘要: 题目来源: https://leetcode.com/problems/maximum-depth-of-binary-tree/ 题意分析: 返回一个树的最大层数。 题目思路: 这里用递归的思想,maxlevel = max( maxleft, maxright) + 1. 代码(python):
阅读全文
posted @ 2016-03-07 18:31 Ry_Chen
阅读(604)
评论(0)
推荐(0)
[LeetCode]题解(python):103-Binary Tree Zigzag Level Order Traversal
摘要: 题目来源: https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ 题意分析: Z字宽度遍历树。 题目思路: 这题可以用比较取巧的方法。首先获得宽度遍历的结果,然后将第二层的翻转就可以了。 代码(python):
阅读全文
posted @ 2016-03-07 18:26 Ry_Chen
阅读(537)
评论(0)
推荐(0)
[LeetCode]题解(python):102- Binary Tree Level Order Traversal
摘要: 题目来源: https://leetcode.com/problems/binary-tree-level-order-traversal/ 题意分析: 宽度优先搜索一颗二叉树,其中同一层的放到同一个list里面。比如: 3 / \ 9 20 / \ 15 7返回 [ [3], [9,20], [1
阅读全文
posted @ 2016-03-07 18:08 Ry_Chen
阅读(559)
评论(0)
推荐(0)
[LeetCode]题解(python):101-Symmetric Tree
摘要: 题目来源: https://leetcode.com/problems/symmetric-tree/ 题意分析: 判断一棵树是不是镜像树。 题目思路: 判断左子树的左右子树是不是和右子树的右左子树相同。 代码(python): # Definition for a binary tree node
阅读全文
posted @ 2016-03-07 17:54 Ry_Chen
阅读(535)
评论(0)
推荐(0)
[LeetCode]题解(python):100-Same Tree
摘要: 题目来源: https://leetcode.com/problems/same-tree/ 题意分析: 判断两棵树是否相等。 题目思路: 用递归的思想,先判断根节点,再判断左右子树。 代码(python): # Definition for a binary tree node. # class
阅读全文
posted @ 2016-03-07 17:46 Ry_Chen
阅读(349)
评论(0)
推荐(0)
[LeetCode]题解(python):099-Recover Binary Search Tree
摘要: 题目来源: https://leetcode.com/problems/recover-binary-search-tree/ 题意分析: 二叉搜索树中有两个点错了位置,恢复这棵树。 题目思路: 如果是没有空间复杂度限制还是比较简单。首先将树的值取出来,然后排序,将相应的位置判断是否正确。如果要特定
阅读全文
posted @ 2016-03-07 17:39 Ry_Chen
阅读(214)
评论(0)
推荐(0)
[LeetCode]题解(python):098- Validate Binary Search Tree
摘要: 题目来源: https://leetcode.com/problems/validate-binary-search-tree/ 题意分析: 给定一个二叉树,判断这个二叉树是否二叉搜索树,也就是严格按照左子树小于等于节点和右子树。 题目思路: 树的题目,我们首先想到的就是递归的思想。这里也可以用递归
阅读全文
posted @ 2016-03-07 17:21 Ry_Chen
阅读(332)
评论(0)
推荐(0)
2016年2月24日
[LeetCode]题解(python):097-Interleaving String
摘要: 题目来源: https://leetcode.com/problems/interleaving-string/ 题意分析: 给定字符串s1,s2,s3,判断s3是否由s1和s2穿插组成。如“abc”由“ac”,“b”组成,而“cba”不是。 题目思路: 这是一个动态规划问题。令ans[i][j]为
阅读全文
posted @ 2016-02-24 21:58 Ry_Chen
阅读(209)
评论(0)
推荐(0)
上一页
1
2
3
4
5
6
7
8
9
10
···
16
下一页
公告