IncredibleThings

导航

上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 28 下一页

2018年10月1日 #

LeetCode - Rotate Image

摘要: 解法1: 先以对角线为轴翻转得到其转置矩阵,再以中间竖轴翻转。 1 2 3 1 4 7 7 4 1 4 5 6 --> 2 5 8 --> 8 5 2 7 8 9 3 6 9 9 6 3 阅读全文

posted @ 2018-10-01 09:58 IncredibleThings 阅读(92) 评论(0) 推荐(0) 编辑

LeetCode - Cut Off Trees for Golf Event

摘要: 我用了priorityqueue+bfs 来做,但没有得到正解,目前不知道错在哪儿。。。😭 阅读全文

posted @ 2018-10-01 08:32 IncredibleThings 阅读(175) 评论(0) 推荐(0) 编辑

2018年9月30日 #

LeetCode - Decode String

摘要: 这道题感觉挺难的,迭代的思想感觉不太容易想 阅读全文

posted @ 2018-09-30 23:18 IncredibleThings 阅读(103) 评论(0) 推荐(0) 编辑

2018年9月28日 #

LeetCode - 4Sum II

摘要: 这道题借鉴了2sum的解法, 创建一个hashmap, 先遍历A,B所有的组合把相反的和和出现次数存进去, 在遍历C,D的所有组合,找匹配。 阅读全文

posted @ 2018-09-28 11:35 IncredibleThings 阅读(89) 评论(0) 推荐(0) 编辑

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) 编辑

2018年9月26日 #

LeetCode - Subtree of Another Tree

摘要: 还是用到了递归和序列化的解法: 阅读全文

posted @ 2018-09-26 11:01 IncredibleThings 阅读(129) 评论(0) 推荐(0) 编辑

LeetCode - Merge Two Binary Trees

摘要: 这道题给了我们两个二叉树,让我们合并成一个,规则是,都存在的结点,就将结点值加起来,否则空的位置就由另一个树的结点来代替。那么根据过往经验,处理二叉树问题的神器就是递归,那么我们来看递归函数如何去写。根据题目中的规则,我们知道如果要处理的相同位置上的两个结点都不存在的话,直接返回即可,如果t1存在, 阅读全文

posted @ 2018-09-26 10:05 IncredibleThings 阅读(120) 评论(0) 推荐(0) 编辑

上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 28 下一页