leetcode.com 2023-11-20
🟡2391.minimum-amount-of-time-to-collect-garbage
🏷️ Tags
#array #string #prefix_sum
🟡2391.minimum-amount-of-time-to-collect-garbage
🏷️ Tags
#array #string #prefix_sum
Telegraph
minimum-amount-of-time-to-collect-garbage
You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the ith house. garbage[i] consists only of the characters 'M', 'P' and 'G' representing one unit of metal, paper and glass garbage respectively. Picking…
leetcode.cn 2023-11-24
🟢2824.count-pairs-whose-sum-is-less-than-target
🏷️ Tags
#array #two_pointers #sorting
🟢2824.count-pairs-whose-sum-is-less-than-target
🏷️ Tags
#array #two_pointers #sorting
Telegraph
count-pairs-whose-sum-is-less-than-target
示例 1: 输入:nums = [-1,1,2,3,1], target = 2 输出:3 解释:总共有 3 个下标对满足题目描述: - (0, 1) ,0 < 1 且 nums[0] + nums[1] = 0 < target - (0, 2) ,0 < 2 且 nums[0] + nums[2] = 1 < target - (0, 4) ,0 < 4 且 nums[0] + nums[4] = 0 < target 注意 (0, 3) 不计入答案因为 nums[0] + nums[3] 不是严格小于…
leetcode.com 2023-11-24
🟡1561.maximum-number-of-coins-you-can-get
🏷️ Tags
#greedy #array #math #game_theory #sorting
🟡1561.maximum-number-of-coins-you-can-get
🏷️ Tags
#greedy #array #math #game_theory #sorting
Telegraph
maximum-number-of-coins-you-can-get
There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:
leetcode.cn 2023-11-25
🟡1457.pseudo-palindromic-paths-in-a-binary-tree
🏷️ Tags
#bit_manipulation #tree #depth_first_search #breadth_first_search #binary_tree
🟡1457.pseudo-palindromic-paths-in-a-binary-tree
🏷️ Tags
#bit_manipulation #tree #depth_first_search #breadth_first_search #binary_tree
Telegraph
pseudo-palindromic-paths-in-a-binary-tree
给你一棵二叉树,每个节点的值为 1 到 9 。我们称二叉树中的一条路径是 「伪回文」的,当它满足:路径经过的所有节点值的排列中,存在一个回文序列。 请你返回从根到叶子节点的所有路径中 伪回文 路径的数目。 示例 1: 输入:root = [2,3,1,3,1,null,1] 输出:2 解释:上图为给定的二叉树。总共有 3 条从根到叶子的路径:红色路径 [2,3,3] ,绿色路径 [2,1,1] 和路径 [2,3,1] 。 在这些路径中,只有红色和绿色的路径是伪回文路径,因为红色路径 [2,3,3] 存在回文排列…
leetcode.com 2023-11-25
🟡1685.sum-of-absolute-differences-in-a-sorted-array
🏷️ Tags
#array #math #prefix_sum
🟡1685.sum-of-absolute-differences-in-a-sorted-array
🏷️ Tags
#array #math #prefix_sum
Telegraph
sum-of-absolute-differences-in-a-sorted-array
You are given an integer array nums sorted in non-decreasing order. Build and return an integer array result with the same length as nums such that result[i] is equal to the summation of absolute differences between nums[i] and all the other elements in the…
leetcode.cn 2023-11-26
🔴828.count-unique-characters-of-all-substrings-of-a-given-string
🏷️ Tags
#hash_table #string #dynamic_programming
🔴828.count-unique-characters-of-all-substrings-of-a-given-string
🏷️ Tags
#hash_table #string #dynamic_programming
Telegraph
count-unique-characters-of-all-substrings-of-a-given-string
我们定义了一个函数 countUniqueChars(s) 来统计字符串 s 中的唯一字符,并返回唯一字符的个数。 例如:s = "LEETCODE" ,则其中 "L", "T","C","O","D" 都是唯一字符,因为它们只出现一次,所以 countUniqueChars(s) = 5 。 本题将会给你一个字符串 s ,我们需要返回 countUniqueChars(t) 的总和,其中 t 是 s 的子字符串。输入用例保证返回值为 32 位整数。 注意,某些子字符串可能是重复的,但你统计时也必须算上…
leetcode.com 2023-11-26
🟡1727.largest-submatrix-with-rearrangements
🏷️ Tags
#greedy #array #matrix #sorting
🟡1727.largest-submatrix-with-rearrangements
🏷️ Tags
#greedy #array #matrix #sorting
Telegraph
largest-submatrix-with-rearrangements
You are given a binary matrix matrix of size m x n, and you are allowed to rearrange the columns of the matrix in any order. Return the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally.…
leetcode.cn 2023-11-27
🟡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
给定一个整数数组 arr,找到 min(b) 的总和,其中 b 的范围为 arr 的每个(连续)子数组。 由于答案可能很大,因此 返回答案模 10^9 + 7 。 示例 1: 输入:arr = [3,1,2,4] 输出:17 解释:子数组为 [3],[1],[2],[4],[3,1],[1,2],[2,4],[3,1,2],[1,2,4],[3,1,2,4]。 最小值为 3,1,2,4,1,1,2,1,1,1,和为 17。 示例 2: 输入:arr = [11,81,94,43,3] 输出:444 …
leetcode.cn 2023-11-28
🟡1670.design-front-middle-back-queue
🏷️ Tags
#design #queue #array #linked_list #data_stream
🟡1670.design-front-middle-back-queue
🏷️ Tags
#design #queue #array #linked_list #data_stream
Telegraph
design-front-middle-back-queue
请你设计一个队列,支持在前,中,后三个位置的 push 和 pop 操作。 请你完成 FrontMiddleBack 类:
leetcode.com 2023-11-28
🔴2147.number-of-ways-to-divide-a-long-corridor
🏷️ Tags
#math #string #dynamic_programming
🔴2147.number-of-ways-to-divide-a-long-corridor
🏷️ Tags
#math #string #dynamic_programming
Telegraph
number-of-ways-to-divide-a-long-corridor
Along a long library corridor, there is a line of seats and decorative plants. You are given a 0-indexed string corridor of length n consisting of letters 'S' and 'P' where each 'S' represents a seat and each 'P' represents a plant. One room divider has already…
leetcode.cn 2023-11-29
🟡2336.smallest-number-in-infinite-set
🏷️ Tags
#design #hash_table #heap_priority_queue
🟡2336.smallest-number-in-infinite-set
🏷️ Tags
#design #hash_table #heap_priority_queue
Telegraph
smallest-number-in-infinite-set
现有一个包含所有正整数的集合 [1, 2, 3, 4, 5, ...] 。 实现 SmallestInfiniteSet 类: