leetcode.com 2024-01-08
🟢938.range-sum-of-bst
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
🟢938.range-sum-of-bst
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
Telegraph
range-sum-of-bst
Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high]. Example 1: Input: root = [10,5,15,3,7,null,18], low = 7, high = 15 Output: 32 Explanation:…
leetcode.cn 2024-01-09
🟡2707.extra-characters-in-a-string
🏷️ Tags
#trie #array #hash_table #string #dynamic_programming
🟡2707.extra-characters-in-a-string
🏷️ Tags
#trie #array #hash_table #string #dynamic_programming
Telegraph
extra-characters-in-a-string
给你一个下标从 0 开始的字符串 s 和一个单词字典 dictionary 。你需要将 s 分割成若干个 互不重叠 的子字符串,每个子字符串都在 dictionary 中出现过。s 中可能会有一些 额外的字符 不在任何子字符串中。 请你采取最优策略分割 s ,使剩下的字符 最少 。 示例 1: 输入:s = "leetscode", dictionary = ["leet","code","leetcode"] 输出:1 解释:将 s 分成两个子字符串:下标从 0 到 3 的 "leet" 和下标从…
leetcode.cn 2024-01-10
🟢2696.minimum-string-length-after-removing-substrings
🏷️ Tags
#stack #string #simulation
🟢2696.minimum-string-length-after-removing-substrings
🏷️ Tags
#stack #string #simulation
Telegraph
minimum-string-length-after-removing-substrings
给你一个仅由 大写 英文字符组成的字符串 s 。 你可以对此字符串执行一些操作,在每一步操作中,你可以从 s 中删除 任一个 "AB" 或 "CD" 子字符串。 通过执行操作,删除所有 "AB" 和 "CD" 子串,返回可获得的最终字符串的 最小 可能长度。 注意,删除子串后,重新连接出的字符串可能会产生新的 "AB" 或 "CD" 子串。 示例 1: 输入:s = "ABFCACDB" 输出:2 解释:你可以执行下述操作: - 从 "ABFCACDB" 中删除子串 "AB",得到 s = "FCACDB"…
leetcode.com 2024-01-10
🟡2385.amount-of-time-for-binary-tree-to-be-infected
🏷️ Tags
#tree #depth_first_search #breadth_first_search #binary_tree
🟡2385.amount-of-time-for-binary-tree-to-be-infected
🏷️ Tags
#tree #depth_first_search #breadth_first_search #binary_tree
Telegraph
amount-of-time-for-binary-tree-to-be-infected
You are given the root of a binary tree with unique values, and an integer start. At minute 0, an infection starts from the node with value start. Each minute, a node becomes infected if:
leetcode.cn 2024-01-11
🟡2645.minimum-additions-to-make-valid-string
🏷️ Tags
#stack #greedy #string #dynamic_programming
🟡2645.minimum-additions-to-make-valid-string
🏷️ Tags
#stack #greedy #string #dynamic_programming
Telegraph
minimum-additions-to-make-valid-string
给你一个字符串 word ,你可以向其中任何位置插入 "a"、"b" 或 "c" 任意次,返回使 word 有效 需要插入的最少字母数。 如果字符串可以由 "abc" 串联多次得到,则认为该字符串 有效 。 示例 1: 输入:word = "b" 输出:2 解释:在 "b" 之前插入 "a" ,在 "b" 之后插入 "c" 可以得到有效字符串 "abc" 。 示例 2: 输入:word = "aaa" 输出:6 解释:在每个 "a" 之后依次插入 "b" 和 "c" 可以得到有效字符串 "abcabcabc"…
leetcode.com 2024-01-11
🟡1026.maximum-difference-between-node-and-ancestor
🏷️ Tags
#tree #depth_first_search #binary_tree
🟡1026.maximum-difference-between-node-and-ancestor
🏷️ Tags
#tree #depth_first_search #binary_tree
Telegraph
maximum-difference-between-node-and-ancestor
Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b. A node a is an ancestor of b if either: any child of a is equal to b or any child of a is an ancestor…
leetcode.cn 2024-01-12
🟢2085.count-common-words-with-one-occurrence
🏷️ Tags
#array #hash_table #string #counting
🟢2085.count-common-words-with-one-occurrence
🏷️ Tags
#array #hash_table #string #counting
Telegraph
count-common-words-with-one-occurrence
给你两个字符串数组 words1 和 words2 ,请你返回在两个字符串数组中 都恰好出现一次 的字符串的数目。 示例 1: 输入:words1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode","is"] 输出:2 解释: - "leetcode" 在两个数组中都恰好出现一次,计入答案。 - "amazing" 在两个数组中都恰好出现一次,计入答案。 - "is" 在两个数组中都出现过,但在 words1…
leetcode.cn 2024-01-13
🟡2182.construct-string-with-repeat-limit
🏷️ Tags
#greedy #string #counting #heap_priority_queue
🟡2182.construct-string-with-repeat-limit
🏷️ Tags
#greedy #string #counting #heap_priority_queue
Telegraph
construct-string-with-repeat-limit
给你一个字符串 s 和一个整数 repeatLimit ,用 s 中的字符构造一个新字符串 repeatLimitedString ,使任何字母 连续 出现的次数都不超过 repeatLimit 次。你不必使用 s 中的全部字符。 返回 字典序最大的 repeatLimitedString 。 如果在字符串 a 和 b 不同的第一个位置,字符串 a 中的字母在字母表中出现时间比字符串 b 对应的字母晚,则认为字符串 a 比字符串 b 字典序更大 。如果字符串中前 min(a.length, b.length)…
leetcode.com 2024-01-13
🟡1347.minimum-number-of-steps-to-make-two-strings-anagram
🏷️ Tags
#hash_table #string #counting
🟡1347.minimum-number-of-steps-to-make-two-strings-anagram
🏷️ Tags
#hash_table #string #counting
Telegraph
minimum-number-of-steps-to-make-two-strings-anagram
You are given two strings of the same length s and t. In one step you can choose any character of t and replace it with another character. Return the minimum number of steps to make t an anagram of s. An Anagram of a string is a string that contains the same…
leetcode.com 2024-01-14
🟡1657.determine-if-two-strings-are-close
🏷️ Tags
#hash_table #string #counting #sorting
🟡1657.determine-if-two-strings-are-close
🏷️ Tags
#hash_table #string #counting #sorting
Telegraph
determine-if-two-strings-are-close
Two strings are considered close if you can attain one from the other using the following operations:
leetcode.com 2024-01-15
🟡2225.find-players-with-zero-or-one-losses
🏷️ Tags
#array #hash_table #counting #sorting
🟡2225.find-players-with-zero-or-one-losses
🏷️ Tags
#array #hash_table #counting #sorting
Telegraph
find-players-with-zero-or-one-losses
You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match. Return a list answer of size 2 where:
leetcode.com 2024-01-16
🟡380.insert-delete-getrandom-o1
🏷️ Tags
#design #array #hash_table #math #randomized
🟡380.insert-delete-getrandom-o1
🏷️ Tags
#design #array #hash_table #math #randomized
Telegraph
insert-delete-getrandom-o1
Implement the RandomizedSet class:
leetcode.cn 2024-01-17
🟢2744.find-maximum-number-of-string-pairs
🏷️ Tags
#array #hash_table #string #simulation
🟢2744.find-maximum-number-of-string-pairs
🏷️ Tags
#array #hash_table #string #simulation
Telegraph
find-maximum-number-of-string-pairs
给你一个下标从 0 开始的数组 words ,数组中包含 互不相同 的字符串。 如果字符串 words[i] 与字符串 words[j] 满足以下条件,我们称它们可以匹配:
leetcode.cn 2024-01-18
🟡2171.removing-minimum-number-of-magic-beans
🏷️ Tags
#array #prefix_sum #sorting
🟡2171.removing-minimum-number-of-magic-beans
🏷️ Tags
#array #prefix_sum #sorting
Telegraph
removing-minimum-number-of-magic-beans
给定一个 正整数 数组 beans ,其中每个整数表示一个袋子里装的魔法豆的数目。 请你从每个袋子中 拿出 一些豆子(也可以 不拿出),使得剩下的 非空 袋子中(即 至少还有一颗 魔法豆的袋子)魔法豆的数目 相等。一旦把魔法豆从袋子中取出,你不能再将它放到任何袋子中。 请返回你需要拿出魔法豆的 最少数目。 示例 1: 输入:beans = [4,1,6,5] 输出:4 解释: - 我们从有 1 个魔法豆的袋子中拿出 1 颗魔法豆。 剩下袋子中魔法豆的数目为:[4,0,6,5] - 然后我们从有 6 个魔法豆的袋子中拿出…