leetcode.cn 2023-11-11
🔴765.couples-holding-hands
🏷️ Tags
#greedy #depth_first_search #breadth_first_search #union_find #graph
🔴765.couples-holding-hands
🏷️ Tags
#greedy #depth_first_search #breadth_first_search #union_find #graph
Telegraph
couples-holding-hands
n 对情侣坐在连续排列的 2n 个座位上,想要牵到对方的手。 人和座位由一个整数数组 row 表示,其中 row[i] 是坐在第 i 个座位上的人的 ID。情侣们按顺序编号,第一对是 (0, 1),第二对是 (2, 3),以此类推,最后一对是 (2n-2, 2n-1)。 返回 最少交换座位的次数,以便每对情侣可以并肩坐在一起。 每次交换可选择任意两人,让他们站起来交换座位。 示例 1: 输入: row = [0,2,1,3] 输出: 1 解释: 只需要交换row[1]和row[2]的位置即可。 示例…
leetcode.com 2023-11-11
🔴2642.design-graph-with-shortest-path-calculator
🏷️ Tags
#graph #design #shortest_path #heap_priority_queue
🔴2642.design-graph-with-shortest-path-calculator
🏷️ Tags
#graph #design #shortest_path #heap_priority_queue
Telegraph
design-graph-with-shortest-path-calculator
There is a directed weighted graph that consists of n nodes numbered from 0 to n - 1. The edges of the graph are initially represented by the given array edges where edges[i] = [fromi, toi, edgeCosti] meaning that there is an edge from fromi to toi with the…
leetcode.cn 2023-11-13
🟡307.range-sum-query-mutable
🏷️ Tags
#design #binary_indexed_tree #segment_tree #array
🟡307.range-sum-query-mutable
🏷️ Tags
#design #binary_indexed_tree #segment_tree #array
Telegraph
range-sum-query-mutable
给你一个数组 nums ,请你完成两类查询。
leetcode.cn 2023-11-14
🟡1334.find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance
🏷️ Tags
#graph #dynamic_programming #shortest_path
🟡1334.find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance
🏷️ Tags
#graph #dynamic_programming #shortest_path
Telegraph
find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance
有 n 个城市,按从 0 到 n-1 编号。给你一个边数组 edges,其中 edges[i] = [fromi, toi, weighti] 代表 fromi 和 toi 两个城市之间的双向加权边,距离阈值是一个整数 distanceThreshold。 返回能通过某些路径到达其他城市数目最少、且路径距离 最大 为 distanceThreshold 的城市。如果有多个这样的城市,则返回编号最大的城市。 注意,连接城市 i 和 j 的路径的距离等于沿该路径的所有边的权重之和。 示例 1: 输入:n…
👍1
leetcode.com 2023-11-14
🟡1930.unique-length-3-palindromic-subsequences
🏷️ Tags
#hash_table #string #prefix_sum
🟡1930.unique-length-3-palindromic-subsequences
🏷️ Tags
#hash_table #string #prefix_sum
Telegraph
unique-length-3-palindromic-subsequences
Given a string s, return the number of unique palindromes of length three that are a subsequence of s. Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once. A palindrome is a string that reads the same forwards…
leetcode.com 2023-11-15
🟡1846.maximum-element-after-decreasing-and-rearranging
🏷️ Tags
#greedy #array #sorting
🟡1846.maximum-element-after-decreasing-and-rearranging
🏷️ Tags
#greedy #array #sorting
Telegraph
maximum-element-after-decreasing-and-rearranging
You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions:
leetcode.cn 2023-11-17
🔴2736.maximum-sum-queries
🏷️ Tags
#stack #binary_indexed_tree #segment_tree #array #binary_search #sorting #monotonic_stack
🔴2736.maximum-sum-queries
🏷️ Tags
#stack #binary_indexed_tree #segment_tree #array #binary_search #sorting #monotonic_stack
Telegraph
maximum-sum-queries
给你两个长度为 n 、下标从 0 开始的整数数组 nums1 和 nums2 ,另给你一个下标从 1 开始的二维数组 queries ,其中 queries[i] = [xi, yi] 。 对于第 i 个查询,在所有满足 nums1[j] >= xi 且 nums2[j] >= yi 的下标 j (0 <= j < n) 中,找出 nums1[j] + nums2[j] 的 最大值 ,如果不存在满足条件的 j 则返回 -1 。 返回数组 answer ,其中 answer[i] 是第 i 个查询的答案。…
leetcode.com 2023-11-17
🟡1877.minimize-maximum-pair-sum-in-array
🏷️ Tags
#greedy #array #two_pointers #sorting
🟡1877.minimize-maximum-pair-sum-in-array
🏷️ Tags
#greedy #array #two_pointers #sorting
Telegraph
minimize-maximum-pair-sum-in-array
The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs.
leetcode.cn 2023-11-18
🟡2342.max-sum-of-a-pair-with-equal-sum-of-digits
🏷️ Tags
#array #hash_table #sorting #heap_priority_queue
🟡2342.max-sum-of-a-pair-with-equal-sum-of-digits
🏷️ Tags
#array #hash_table #sorting #heap_priority_queue
Telegraph
max-sum-of-a-pair-with-equal-sum-of-digits
给你一个下标从 0 开始的数组 nums ,数组中的元素都是 正 整数。请你选出两个下标 i 和 j(i != j),且 nums[i] 的数位和 与 nums[j] 的数位和相等。 请你找出所有满足条件的下标 i 和 j ,找出并返回 nums[i] + nums[j] 可以得到的 最大值 。 示例 1: 输入:nums = [18,43,36,13,7] 输出:54 解释:满足条件的数对 (i, j) 为: - (0, 2) ,两个数字的数位和都是 9 ,相加得到 18 + 36 = 54 。…
leetcode.com 2023-11-18
🟡1838.frequency-of-the-most-frequent-element
🏷️ Tags
#greedy #array #binary_search #prefix_sum #sorting #sliding_window
🟡1838.frequency-of-the-most-frequent-element
🏷️ Tags
#greedy #array #binary_search #prefix_sum #sorting #sliding_window
Telegraph
frequency-of-the-most-frequent-element
The frequency of an element is the number of times it occurs in an array. You are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1. Return the maximum possible frequency…
leetcode.cn 2023-11-19
🔴689.maximum-sum-of-3-non-overlapping-subarrays
🏷️ Tags
#array #dynamic_programming
🔴689.maximum-sum-of-3-non-overlapping-subarrays
🏷️ Tags
#array #dynamic_programming
Telegraph
maximum-sum-of-3-non-overlapping-subarrays
给你一个整数数组 nums 和一个整数 k ,找出三个长度为 k 、互不重叠、且全部数字和(3 * k 项)最大的子数组,并返回这三个子数组。 以下标的数组形式返回结果,数组中的每一项分别指示每个子数组的起始位置(下标从 0 开始)。如果有多个结果,返回字典序最小的一个。 示例 1: 输入:nums = [1,2,1,2,6,7,5,1], k = 2 输出:[0,3,5] 解释:子数组 [1, 2], [2, 6], [7, 5] 对应的起始下标为 [0, 3, 5]。 也可以取 [2, 1], 但是结果…
leetcode.com 2023-11-19
🟡1887.reduction-operations-to-make-the-array-elements-equal
🏷️ Tags
#array #sorting
🟡1887.reduction-operations-to-make-the-array-elements-equal
🏷️ Tags
#array #sorting
Telegraph
reduction-operations-to-make-the-array-elements-equal
Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps:
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…