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 个魔法豆的袋子中拿出…
leetcode.cn 2024-01-19
🔴2809.minimum-time-to-make-array-sum-at-most-x
🏷️ Tags
#array #dynamic_programming #sorting
🔴2809.minimum-time-to-make-array-sum-at-most-x
🏷️ Tags
#array #dynamic_programming #sorting
Telegraph
minimum-time-to-make-array-sum-at-most-x
给你两个长度相等下标从 0 开始的整数数组 nums1 和 nums2 。每一秒,对于所有下标 0 <= i < nums1.length ,nums1[i] 的值都增加 nums2[i] 。操作 完成后 ,你可以进行如下操作:
leetcode.com 2024-01-20
🟡907.sum-of-subarray-minimums
🏷️ Tags
#stack #array #dynamic_programming #monotonic_stack
🟡907.sum-of-subarray-minimums
🏷️ Tags
#stack #array #dynamic_programming #monotonic_stack
Telegraph
sum-of-subarray-minimums
Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 109 + 7. Example 1: Input: arr = [3,1,2,4] Output: 17 Explanation: Subarrays are [3]…