上一页 1 ··· 3 4 5 6 7
摘要: 这道题为简单题 题目: 思路: 利用广搜,对每个节点进行判断,是否它的左儿子存在,并且它左儿子的左右儿子都不存在,那么total就加上它左儿子的值 代码: 阅读全文
posted @ 2017-09-07 15:05 唐僧洗发爱飘柔 阅读(103) 评论(0) 推荐(0)
摘要: 这道题为简单题 题目: Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally 阅读全文
posted @ 2017-09-07 14:57 唐僧洗发爱飘柔 阅读(150) 评论(0) 推荐(0)
摘要: 这道题为简单题 题目: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the 阅读全文
posted @ 2017-09-06 22:52 唐僧洗发爱飘柔 阅读(107) 评论(0) 推荐(0)
摘要: 这道题属于容易,还是挺简单的,但是我用的方法比较复杂。 题目: 思路: 1、我的想法是把树转换成列表,然后再遍历这个列表,判断是否两个元素相加为0,这种方法时间复杂度较高 2、大神也是将树节点存在列表中,建立一个空集合set,遍历列表,如果该(k - 该节点值)在集合中则返回True,否则将该节点值 阅读全文
posted @ 2017-09-06 11:51 唐僧洗发爱飘柔 阅读(126) 评论(0) 推荐(0)
摘要: 这道题属于容易,我们要知道二叉搜索树的一个特点:左子节点比父节点低,右子节点比父节点高 题目: Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all 阅读全文
posted @ 2017-09-05 23:31 唐僧洗发爱飘柔 阅读(113) 评论(0) 推荐(0)
摘要: 这道题被标记为简单,学过广搜(BFS)应该会很容易做出来 题目: 思路: BFS算法搜索每一层的节点,并把他们保存在一个列表a中,再利用循环将这一层的total加起来,并判断当前节点是否有子节点,有就添加到列表的后面,当搜索完一层的节点,就计算每一层的平均值并添加到另外一个新的列表b中,然后再判断是 阅读全文
posted @ 2017-09-05 20:06 唐僧洗发爱飘柔 阅读(119) 评论(0) 推荐(0)
摘要: 这个题被标记为easy,还是挺简单的,但因为我才入门,其实也碰到了一些问题 题目要求: Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two 阅读全文
posted @ 2017-09-02 23:56 唐僧洗发爱飘柔 阅读(122) 评论(0) 推荐(0)
摘要: 本人才接触这个领域,学识尚浅,发表的内容仅是一些个人的理解,如有不对,欢迎大家的评论区里指出。 阅读全文
posted @ 2017-09-02 21:14 唐僧洗发爱飘柔 阅读(104) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7