leetcode.com 2023-05-21
🟡934.shortest-bridge
🏷️ Tags
#depth_first_search #breadth_first_search #array #matrix
🟡934.shortest-bridge
🏷️ Tags
#depth_first_search #breadth_first_search #array #matrix
Telegraph
shortest-bridge
You are given an n x n binary matrix grid where 1 represents land and 0 represents water. An island is a 4-directionally connected group of 1's not connected to any other 1's. There are exactly two islands in grid. You may change 0's to 1's to connect the…
leetcode.cn 2023-05-22
🟡1080.insufficient-nodes-in-root-to-leaf-paths
🏷️ Tags
#tree #depth_first_search #binary_tree
🟡1080.insufficient-nodes-in-root-to-leaf-paths
🏷️ Tags
#tree #depth_first_search #binary_tree
Telegraph
insufficient-nodes-in-root-to-leaf-paths
给你二叉树的根节点 root 和一个整数 limit ,请你同时删除树中所有 不足节点 ,并返回最终二叉树的根节点。 假如通过节点 node 的每种可能的 “根-叶” 路径上值的总和全都小于给定的 limit,则该节点被称之为 不足节点 ,需要被删除。 叶子节点,就是没有子节点的节点。 示例 1: 输入:root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1 输出:[1,2,3,4,null,null,7,8,9,null,14]…
leetcode.com 2023-05-22
🟡347.top-k-frequent-elements
🏷️ Tags
#array #hash_table #divide_and_conquer #bucket_sort #counting #quickselect #sorting #heap_priority_queue
🟡347.top-k-frequent-elements
🏷️ Tags
#array #hash_table #divide_and_conquer #bucket_sort #counting #quickselect #sorting #heap_priority_queue
Telegraph
top-k-frequent-elements
Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1] Constraints:
leetcode.com 2023-05-23
🟢703.kth-largest-element-in-a-stream
🏷️ Tags
#tree #design #binary_search_tree #binary_tree #data_stream #heap_priority_queue
🟢703.kth-largest-element-in-a-stream
🏷️ Tags
#tree #design #binary_search_tree #binary_tree #data_stream #heap_priority_queue
Telegraph
kth-largest-element-in-a-stream
Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Implement KthLargest class:
leetcode.cn 2023-05-24
🔴1377.frog-position-after-t-seconds
🏷️ Tags
#tree #depth_first_search #breadth_first_search #graph
🔴1377.frog-position-after-t-seconds
🏷️ Tags
#tree #depth_first_search #breadth_first_search #graph
Telegraph
frog-position-after-t-seconds
给你一棵由 n 个顶点组成的无向树,顶点编号从 1 到 n。青蛙从 顶点 1 开始起跳。规则如下:
leetcode.com 2023-05-24
🟡2542.maximum-subsequence-score
🏷️ Tags
#greedy #array #sorting #heap_priority_queue
🟡2542.maximum-subsequence-score
🏷️ Tags
#greedy #array #sorting #heap_priority_queue
Telegraph
maximum-subsequence-score
You are given two 0-indexed integer arrays nums1 and nums2 of equal length n and a positive integer k. You must choose a subsequence of indices from nums1 of length k. For chosen indices i0, i1, ..., ik - 1, your score is defined as:
leetcode.com 2023-05-25
🟡837.new-21-game
🏷️ Tags
#math #dynamic_programming #sliding_window #probability_and_statistics
🟡837.new-21-game
🏷️ Tags
#math #dynamic_programming #sliding_window #probability_and_statistics
Telegraph
new-21-game
Alice plays the following game, loosely based on the card game "21". Alice starts with 0 points and draws numbers while she has less than k points. During each draw, she gains an integer number of points randomly from the range [1, maxPts], where maxPts is…
leetcode.cn 2023-05-27
🟡1093.statistics-from-a-large-sample
🏷️ Tags
#array #math #probability_and_statistics
🟡1093.statistics-from-a-large-sample
🏷️ Tags
#array #math #probability_and_statistics
Telegraph
statistics-from-a-large-sample
我们对 0 到 255 之间的整数进行采样,并将结果存储在数组 count 中:count[k] 就是整数 k 在样本中出现的次数。 计算以下统计数据:
leetcode.cn 2023-05-28
🔴1439.find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows
🏷️ Tags
#array #binary_search #matrix #heap_priority_queue
🔴1439.find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows
🏷️ Tags
#array #binary_search #matrix #heap_priority_queue
Telegraph
find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows
给你一个 m * n 的矩阵 mat,以及一个整数 k ,矩阵中的每一行都以非递减的顺序排列。 你可以从每一行中选出 1 个元素形成一个数组。返回所有可能数组中的第 k 个 最小 数组和。 示例 1: 输入:mat = [[1,3,11],[2,4,6]], k = 5 输出:7 解释:从每一行中选出一个元素,前 k 个和最小的数组分别是: [1,2], [1,4], [3,2], [3,4], [1,6]。其中第 5 个的和是 7 。 示例 2: 输入:mat = [[1,3,11],[2,4,6]]…
leetcode.cn 2023-05-29
🟢2455.average-value-of-even-numbers-that-are-divisible-by-three
🏷️ Tags
#array #math
🟢2455.average-value-of-even-numbers-that-are-divisible-by-three
🏷️ Tags
#array #math
Telegraph
average-value-of-even-numbers-that-are-divisible-by-three
给你一个由正整数组成的整数数组 nums ,返回其中可被 3 整除的所有偶数的平均值。 注意:n 个元素的平均值等于 n 个元素 求和 再除以 n ,结果 向下取整 到最接近的整数。 示例 1: 输入:nums = [1,3,6,10,12,15] 输出:9 解释:6 和 12 是可以被 3 整除的偶数。(6 + 12) / 2 = 9 。 示例 2: 输入:nums = [1,2,4,7,10] 输出:0 解释:不存在满足题目要求的整数,所以返回 0 。 提示:
leetcode.cn 2023-05-30
🟡1110.delete-nodes-and-return-forest
🏷️ Tags
#tree #depth_first_search #array #hash_table #binary_tree
🟡1110.delete-nodes-and-return-forest
🏷️ Tags
#tree #depth_first_search #array #hash_table #binary_tree
Telegraph
delete-nodes-and-return-forest
给出二叉树的根节点 root,树上每个节点都有一个不同的值。 如果节点值在 to_delete 中出现,我们就把该节点从树上删去,最后得到一个森林(一些不相交的树构成的集合)。 返回森林中的每棵树。你可以按任意顺序组织答案。 示例 1: 输入:root = [1,2,3,4,5,6,7], to_delete = [3,5] 输出:[[1,2,null,4],[6],[7]] 示例 2: 输入:root = [1,2,4,null,3], to_delete = [3] 输出:[[1,2,4]] …