IncredibleThings

导航

2018年9月27日 #

LeetCode - Most Frequent Subtree Sum

摘要: 我们想下子树有何特点,必须是要有叶结点,单独的一个叶结点也可以当作是子树,那么子树是从下往上构建的,这种特点很适合使用后序遍历,我们使用一个哈希表来建立子树和跟其出现频率的映射,用一个变量cnt来记录当前最多的次数,递归函数返回的是以当前结点为根结点的子树结点值之和,然后在递归函数中,我们先对当前结 阅读全文

posted @ 2018-09-27 19:59 IncredibleThings 阅读(91) 评论(0) 推荐(0) 编辑

LeetCode - Encode and Decode TinyURL

摘要: TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http 阅读全文

posted @ 2018-09-27 11:47 IncredibleThings 阅读(100) 评论(0) 推荐(0) 编辑

LeetCode - Diameter of Binary Tree

摘要: Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may ... 阅读全文

posted @ 2018-09-27 11:19 IncredibleThings 阅读(84) 评论(0) 推荐(0) 编辑

LeetCode - Boundary of Binary Tree

摘要: 这道题给了我们一棵二叉树,让我们以逆时针的顺序来输出树的边界,按顺序分别为左边界,叶结点和右边界。题目中给的例子也能让我们很清晰的明白哪些算是边界上的结点。那么最直接的方法就是分别按顺序求出左边界结点,叶结点,和右边界结点。那么如何求的,对于树的操作肯定是用递归最简洁啊,所以我们可以写分别三个递归函 阅读全文

posted @ 2018-09-27 09:11 IncredibleThings 阅读(184) 评论(0) 推荐(0) 编辑