IncredibleThings

导航

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

2018年9月26日 #

LeetCode - Palindromic Substrings

摘要: 暴力解法, 注意要分情况讨论: 二刷: 阅读全文

posted @ 2018-09-26 09:04 IncredibleThings 阅读(139) 评论(0) 推荐(0) 编辑

2018年9月25日 #

LeetCode - Find Duplicate Subtrees

摘要: 这道题考的是DFS+序列化二叉树 我们将每一个节点的左子节点的值和右结点的值都存储下来,组成一个字符串,作为索引,将对应节点保存到map里。 如果一样的字符串已经出现过一次了,我们就把他的root保存在要返回的list中: 阅读全文

posted @ 2018-09-25 19:51 IncredibleThings 阅读(127) 评论(0) 推荐(0) 编辑

LeetCode - Two Sum IV - Input is a BST

摘要: 只要是两数之和的题,一定要记得用哈希表来做,这道题只不过是把数组变成了一棵二叉树而已 阅读全文

posted @ 2018-09-25 10:54 IncredibleThings 阅读(116) 评论(0) 推荐(0) 编辑

LeetCode - Find K Closest Elements

摘要: 中了 priorityqueue 的毒,自己写了个比较繁琐的方法: 更合适的方法: 用binary search + 双指针来做, 注意最后加入list中的顺序问题: 阅读全文

posted @ 2018-09-25 10:37 IncredibleThings 阅读(612) 评论(0) 推荐(0) 编辑

2018年9月24日 #

LeetCode - Trim a Binary Search Tree

摘要: 正确方法其实应该是在遍历的过程中就修改二叉树,移除不合题意的结点。当然对于二叉树的题,十有八九都是要用递归来解的。首先判断如果root为空,那么直接返回空即可。然后就是要看根结点是否在范围内,如果根结点值小于L,那么返回对其右子结点调用递归函数的值;如果根结点大于R,那么返回对其左子结点调用递归函数 阅读全文

posted @ 2018-09-24 19:32 IncredibleThings 阅读(106) 评论(0) 推荐(0) 编辑

LeetCode - Top K Frequent Words

摘要: 先用 hashmap 存储string 和出现次数的映射, 然后insert并维持一个size为K的priorityqueue (注意要自己定义compare 函数),最后会得到top Kth words 但是是从小到大排序,注意要reverse: 阅读全文

posted @ 2018-09-24 04:41 IncredibleThings 阅读(145) 评论(0) 推荐(0) 编辑

LeetCode - Number of Distinct Islands

摘要: 这道题让我们求不同岛屿的个数,是之前那道Number of Islands的拓展,这道题的难点是如何去判断两个岛屿是否是不同的岛屿,首先1的个数肯定是要相同,但是1的个数相同不能保证一定是相同的岛屿,比如例子2中的那两个岛屿的就不相同,就是说两个相同的岛屿通过平移可以完全重合,但是不能旋转。那么我们 阅读全文

posted @ 2018-09-24 03:21 IncredibleThings 阅读(117) 评论(0) 推荐(0) 编辑

LeetCode - Max Area of Island

摘要: BFS + 涂色法: 阅读全文

posted @ 2018-09-24 01:05 IncredibleThings 阅读(109) 评论(0) 推荐(0) 编辑

2018年9月23日 #

LeetCode - Kth Largest Element in a Stream

摘要: 遍历数组时将数字加入优先队列(堆),一旦堆的大小大于k就将堆顶元素去除,确保堆的大小为k。遍历完后堆顶就是返回值。 阅读全文

posted @ 2018-09-23 23:46 IncredibleThings 阅读(92) 评论(0) 推荐(0) 编辑

LeetCode - Flood Fill

摘要: An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535). Given a coordinate (sr, sc) representing the starting pixel (row and col... 阅读全文

posted @ 2018-09-23 21:05 IncredibleThings 阅读(136) 评论(0) 推荐(0) 编辑

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