leetcode.cn 2023-06-09
🔴2699.modify-graph-edge-weights
🏷️ Tags
#graph #shortest_path #heap_priority_queue
🔴2699.modify-graph-edge-weights
🏷️ Tags
#graph #shortest_path #heap_priority_queue
Telegraph
modify-graph-edge-weights
给你一个 n 个节点的 无向带权连通 图,节点编号为 0 到 n - 1 ,再给你一个整数数组 edges ,其中 edges[i] = [ai, bi, wi] 表示节点 ai 和 bi 之间有一条边权为 wi 的边。 部分边的边权为 -1(wi = -1),其他边的边权都为 正 数(wi > 0)。 你需要将所有边权为 -1 的边都修改为范围 [1, 2 * 109] 中的 正整数 ,使得从节点 source 到节点 destination 的 最短距离 为整数 target 。如果有 多种 修改方案可以使 source…
leetcode.cn 2023-06-10
🟡1170.compare-strings-by-frequency-of-the-smallest-character
🏷️ Tags
#array #hash_table #string #binary_search #sorting
🟡1170.compare-strings-by-frequency-of-the-smallest-character
🏷️ Tags
#array #hash_table #string #binary_search #sorting
Telegraph
compare-strings-by-frequency-of-the-smallest-character
定义一个函数 f(s),统计 s 中(按字典序比较)最小字母的出现频次 ,其中 s 是一个非空字符串。 例如,若 s = "dcce",那么 f(s) = 2,因为字典序最小字母是 "c",它出现了 2 次。 现在,给你两个字符串数组待查表 queries 和词汇表 words 。对于每次查询 queries[i] ,需统计 words 中满足 f(queries[i]) < f(W) 的 词的数目 ,W 表示词汇表 words 中的每个词。 请你返回一个整数数组 answer 作为答案,其中每个 answer[i] 是第…
leetcode.com 2023-06-10
🟡1802.maximum-value-at-a-given-index-in-a-bounded-array
🏷️ Tags
#greedy #binary_search
🟡1802.maximum-value-at-a-given-index-in-a-bounded-array
🏷️ Tags
#greedy #binary_search
Telegraph
maximum-value-at-a-given-index-in-a-bounded-array
You are given three positive integers: n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions:
leetcode.cn 2023-06-11
🟡1171.remove-zero-sum-consecutive-nodes-from-linked-list
🏷️ Tags
#hash_table #linked_list
🟡1171.remove-zero-sum-consecutive-nodes-from-linked-list
🏷️ Tags
#hash_table #linked_list
Telegraph
remove-zero-sum-consecutive-nodes-from-linked-list
给你一个链表的头节点 head,请你编写代码,反复删去链表中由 总和 值为 0 的连续节点组成的序列,直到不存在这样的序列为止。 删除完毕后,请你返回最终结果链表的头节点。 你可以返回任何满足题目要求的答案。 (注意,下面示例中的所有序列,都是对 ListNode 对象序列化的表示。) 示例 1: 输入:head = [1,2,-3,3,1] 输出:[3,1] 提示:答案 [1,2,1] 也是正确的。 示例 2: 输入:head = [1,2,3,-3,4] 输出:[1,2,4] 示例 3: 输入:head…
leetcode.cn 2023-06-12
🔴1483.kth-ancestor-of-a-tree-node
🏷️ Tags
#tree #depth_first_search #breadth_first_search #design #binary_search #dynamic_programming
🔴1483.kth-ancestor-of-a-tree-node
🏷️ Tags
#tree #depth_first_search #breadth_first_search #design #binary_search #dynamic_programming
Telegraph
kth-ancestor-of-a-tree-node
给你一棵树,树上有 n 个节点,按从 0 到 n-1 编号。树以父节点数组的形式给出,其中 parent[i] 是节点 i 的父节点。树的根节点是编号为 0 的节点。 树节点的第 k 个祖先节点是从该节点到根节点路径上的第 k 个节点。 实现 TreeAncestor 类:
leetcode.com 2023-06-13
🟡2352.equal-row-and-column-pairs
🏷️ Tags
#array #hash_table #matrix #simulation
🟡2352.equal-row-and-column-pairs
🏷️ Tags
#array #hash_table #matrix #simulation
Telegraph
equal-row-and-column-pairs
Given a 0-indexed n x n integer matrix grid, return the number of pairs (ri, cj) such that row ri and column cj are equal. A row and column pair is considered equal if they contain the same elements in the same order (i.e., an equal array). Example 1: Input:…
leetcode.com 2023-06-14
🟢530.minimum-absolute-difference-in-bst
🏷️ Tags
#tree #depth_first_search #breadth_first_search #binary_search_tree #binary_tree
🟢530.minimum-absolute-difference-in-bst
🏷️ Tags
#tree #depth_first_search #breadth_first_search #binary_search_tree #binary_tree
Telegraph
minimum-absolute-difference-in-bst
Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree. Example 1: Input: root = [4,2,6,1,3] Output: 1 Example 2: Input: root = [1,0,48,null,null,12,49] Output: 1 …
leetcode.cn 2023-06-15
🟡1177.can-make-palindrome-from-substring
🏷️ Tags
#bit_manipulation #array #hash_table #string #prefix_sum
🟡1177.can-make-palindrome-from-substring
🏷️ Tags
#bit_manipulation #array #hash_table #string #prefix_sum
Telegraph
can-make-palindrome-from-substring
给你一个字符串 s,请你对 s 的子串进行检测。 每次检测,待检子串都可以表示为 queries[i] = [left, right, k]。我们可以 重新排列 子串 s[left], ..., s[right],并从中选择 最多 k 项替换成任何小写英文字母。 如果在上述检测过程中,子串可以变成回文形式的字符串,那么检测结果为 true,否则结果为 false。 返回答案数组 answer[],其中 answer[i] 是第 i 个待检子串 queries[i] 的检测结果。 注意:在替换时,子串中的每个字母都必须作为…
leetcode.com 2023-06-15
🟡1161.maximum-level-sum-of-a-binary-tree
🏷️ Tags
#tree #depth_first_search #breadth_first_search #binary_tree
🟡1161.maximum-level-sum-of-a-binary-tree
🏷️ Tags
#tree #depth_first_search #breadth_first_search #binary_tree
Telegraph
maximum-level-sum-of-a-binary-tree
Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that the sum of all the values of nodes at level x is maximal. Example 1: Input: root = [1,7,0,7,-8,null,null] Output:…
leetcode.cn 2023-06-16
🔴1494.parallel-courses-ii
🏷️ Tags
#bit_manipulation #graph #dynamic_programming #bitmask
🔴1494.parallel-courses-ii
🏷️ Tags
#bit_manipulation #graph #dynamic_programming #bitmask
Telegraph
parallel-courses-ii
给你一个整数 n 表示某所大学里课程的数目,编号为 1 到 n ,数组 relations 中, relations[i] = [xi, yi] 表示一个先修课的关系,也就是课程 xi 必须在课程 yi 之前上。同时你还有一个整数 k 。 在一个学期中,你 最多 可以同时上 k 门课,前提是这些课的先修课在之前的学期里已经上过了。 请你返回上完所有课最少需要多少个学期。题目保证一定存在一种上完所有课的方式。 示例 1: 输入:n = 4, relations = [[2,1],[3,1],[1,4]]…
leetcode.com 2023-06-16
🔴1569.number-of-ways-to-reorder-array-to-get-same-bst
🏷️ Tags
#tree #union_find #binary_search_tree #memoization #array #math #divide_and_conquer #dynamic_programming #binary_tree #combinatorics
🔴1569.number-of-ways-to-reorder-array-to-get-same-bst
🏷️ Tags
#tree #union_find #binary_search_tree #memoization #array #math #divide_and_conquer #dynamic_programming #binary_tree #combinatorics
Telegraph
number-of-ways-to-reorder-array-to-get-same-bst
Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nums in order into an initially empty BST. Find the number of different ways to reorder nums so that…
leetcode.com 2023-06-17
🔴1187.make-array-strictly-increasing
🏷️ Tags
#array #binary_search #dynamic_programming #sorting
🔴1187.make-array-strictly-increasing
🏷️ Tags
#array #binary_search #dynamic_programming #sorting
Telegraph
make-array-strictly-increasing
Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing. In one operation, you can choose two indices 0 <= i < arr1.length and 0 <= j < arr2.length and do the assignment arr1[i]…
leetcode.cn 2023-06-18
🟡1254.number-of-closed-islands
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #matrix
🟡1254.number-of-closed-islands
🏷️ Tags
#depth_first_search #breadth_first_search #union_find #array #matrix
Telegraph
number-of-closed-islands
二维矩阵 grid 由 0 (土地)和 1 (水)组成。岛是由最大的4个方向连通的 0 组成的群,封闭岛是一个 完全 由1包围(左、上、右、下)的岛。 请返回 封闭岛屿 的数目。 示例 1: 输入:grid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1,0,1],[1,1,1,1,1,1,1,0]] 输出:2 解释: 灰色区域的岛屿是封闭岛屿,因为这座岛屿完全被水域包围(即被 1 区域包围)。 示例 2: 输入:grid…
leetcode.com 2023-06-18
🔴2328.number-of-increasing-paths-in-a-grid
🏷️ Tags
#depth_first_search #breadth_first_search #graph #topological_sort #memoization #array #dynamic_programming #matrix
🔴2328.number-of-increasing-paths-in-a-grid
🏷️ Tags
#depth_first_search #breadth_first_search #graph #topological_sort #memoization #array #dynamic_programming #matrix
Telegraph
number-of-increasing-paths-in-a-grid
You are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions. Return the number of strictly increasing paths in the grid such that you can start from any cell and end at any cell. Since the answer may…