Fork me on GitHub
摘要: 层数最深叶子节点的和 Deepest Leaves Sum 一棵二叉树的根节点root,返回层数最深的叶子节点的和。 in: root = [1,2,3,4,5,null,6,7,null,null,null,null,8] out:15 思路 对树的处理基本就是 DFS,BFS。 看到一个非常有意 阅读全文
posted @ 2021-10-19 00:18 WilliamCui 阅读(89) 评论(0) 推荐(0) 编辑
摘要: 首个公共祖先 First Common Ancestor 如何找出二叉树中某两个节点的第一个共同祖先。不得将其他的节点存储在另外的数据结构中。不一定是BST [3,4,1,6,2,9,8,null,null,7,5], p = 6, q = 2 公共祖先就是4 p=6,q = 5,公共祖先就是4 p 阅读全文
posted @ 2021-10-19 00:02 WilliamCui 阅读(87) 评论(0) 推荐(0) 编辑
摘要: Top K Frequent Words 前K个高频单词 给一非空的单词列表,返回前 k 个出现次数最多的单词。 返回的答案应该按单词出现频率由高到低排序。如果不同的单词有相同出现频率,按字母顺序排序。 输入: ["i", "love", "leetcode", "i", "love", "codi 阅读全文
posted @ 2021-10-15 00:22 WilliamCui 阅读(49) 评论(0) 推荐(0) 编辑
摘要: Kth Largest Element in an Array 数组中的第K个最大元素 在未排序的数组中找到第 k 个最大的元素 输入: [3,2,1,5,6,4] 和 k = 2 输出: 5 思路 可以通过小顶堆, 并且将堆大小保持在k。此时堆顶节点都是需要的结果。 public int find 阅读全文
posted @ 2021-10-15 00:14 WilliamCui 阅读(37) 评论(0) 推荐(0) 编辑
摘要: 搜索旋转排序数组 Search in Rotated Sorted Array II There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values). Befor 阅读全文
posted @ 2021-10-14 20:55 WilliamCui 阅读(32) 评论(0) 推荐(0) 编辑
摘要: 排序数组中查找元素的第一个和最后一个位置 Find First And Last Position of Element in Sorted Array 给定一个非递减排序数组nums 和目标target.找到target在数组中的开始位置和结束位置。如果数组中不存在这个数,返回[-1,-1] nu 阅读全文
posted @ 2021-10-13 13:55 WilliamCui 阅读(72) 评论(0) 推荐(0) 编辑
摘要: 两数和 Two Sum 给定一个数组nums,一个target,在nums中寻找一组不重复的组合之和等于target,数组中必然存在一组数满足要求。 in: nums = [2,7,11,15], target = 9 out:[0,1] 思路 借助map,在遍历的过程中寻找map中是否存在targ 阅读全文
posted @ 2021-10-12 17:15 WilliamCui 阅读(52) 评论(0) 推荐(0) 编辑
摘要: Find K Pairs with Smallest Sums 查找和最小的K对数字 You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define a pair 阅读全文
posted @ 2021-10-11 11:43 WilliamCui 阅读(37) 评论(0) 推荐(0) 编辑
摘要: 被包围的区域 Surrounded Regions 有一个 m*n的矩阵,每个坐标都有字符X ,O组成,找到所有被X包围的O区域。 将O换成X in:[["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X 阅读全文
posted @ 2021-10-11 09:30 WilliamCui 阅读(65) 评论(0) 推荐(0) 编辑
摘要: Kth Largest Element in a Stream 数据流中的第 K 大元素 Design a class to find the kth largest element in a stream. Note that it is the kth largest element in th 阅读全文
posted @ 2021-10-11 09:30 WilliamCui 阅读(21) 评论(0) 推荐(0) 编辑