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 类:
leetcode.com 2023-11-30
🔴1611.minimum-one-bit-operations-to-make-integers-zero
🏷️ Tags
#bit_manipulation #memoization #dynamic_programming
🔴1611.minimum-one-bit-operations-to-make-integers-zero
🏷️ Tags
#bit_manipulation #memoization #dynamic_programming
Telegraph
minimum-one-bit-operations-to-make-integers-zero
Given an integer n, you must transform it into 0 using the following operations any number of times:
leetcode.cn 2023-12-02
🟡1094.car-pooling
🏷️ Tags
#array #prefix_sum #sorting #simulation #heap_priority_queue
🟡1094.car-pooling
🏷️ Tags
#array #prefix_sum #sorting #simulation #heap_priority_queue
Telegraph
car-pooling
车上最初有 capacity 个空座位。车 只能 向一个方向行驶(也就是说,不允许掉头或改变方向) 给定整数 capacity 和一个数组 trips , trip[i] = [numPassengersi, fromi, toi] 表示第 i 次旅行有 numPassengersi 乘客,接他们和放他们的位置分别是 fromi 和 toi 。这些位置是从汽车的初始位置向东的公里数。 当且仅当你可以在所有给定的行程中接送所有乘客时,返回 true,否则请返回 false。 示例 1: 输入:trips…
leetcode.com 2023-12-02
🟢1160.find-words-that-can-be-formed-by-characters
🏷️ Tags
#array #hash_table #string
🟢1160.find-words-that-can-be-formed-by-characters
🏷️ Tags
#array #hash_table #string
Telegraph
find-words-that-can-be-formed-by-characters
You are given an array of strings words and a string chars. A string is good if it can be formed by characters from chars (each character can only be used once). Return the sum of lengths of all good strings in words. Example 1: Input: words = ["cat","bt"…
leetcode.cn 2023-12-03
🟡1423.maximum-points-you-can-obtain-from-cards
🏷️ Tags
#array #prefix_sum #sliding_window
🟡1423.maximum-points-you-can-obtain-from-cards
🏷️ Tags
#array #prefix_sum #sliding_window
Telegraph
maximum-points-you-can-obtain-from-cards
几张卡牌 排成一行,每张卡牌都有一个对应的点数。点数由整数数组 cardPoints 给出。 每次行动,你可以从行的开头或者末尾拿一张卡牌,最终你必须正好拿 k 张卡牌。 你的点数就是你拿到手中的所有卡牌的点数之和。 给你一个整数数组 cardPoints 和整数 k,请你返回可以获得的最大点数。 示例 1: 输入:cardPoints = [1,2,3,4,5,6,1], k = 3 输出:12 解释:第一次行动,不管拿哪张牌,你的点数总是 1 。但是,先拿最右边的卡牌将会最大化你的可获得点数。最…
leetcode.cn 2023-12-04
🟡1038.binary-search-tree-to-greater-sum-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
🟡1038.binary-search-tree-to-greater-sum-tree
🏷️ Tags
#tree #depth_first_search #binary_search_tree #binary_tree
Telegraph
binary-search-tree-to-greater-sum-tree
给定一个二叉搜索树 root (BST),请将它的每个节点的值替换成树中大于或者等于该节点值的所有节点值之和。 提醒一下, 二叉搜索树 满足下列约束条件:
leetcode.cn 2023-12-05
🟡2477.minimum-fuel-cost-to-report-to-the-capital
🏷️ Tags
#tree #depth_first_search #breadth_first_search #graph
🟡2477.minimum-fuel-cost-to-report-to-the-capital
🏷️ Tags
#tree #depth_first_search #breadth_first_search #graph
Telegraph
minimum-fuel-cost-to-report-to-the-capital
给你一棵 n 个节点的树(一个无向、连通、无环图),每个节点表示一个城市,编号从 0 到 n - 1 ,且恰好有 n - 1 条路。0 是首都。给你一个二维整数数组 roads ,其中 roads[i] = [ai, bi] ,表示城市 ai 和 bi 之间有一条 双向路 。 每个城市里有一个代表,他们都要去首都参加一个会议。 每座城市里有一辆车。给你一个整数 seats 表示每辆车里面座位的数目。 城市里的代表可以选择乘坐所在城市的车,或者乘坐其他城市的车。相邻城市之间一辆车的油耗是一升汽油。 请你返回到达首都最少需要多少升汽油。…
❤1