原文链接: https://leetcode-cn.com/problems/minimum-interval-to-include-each-query 英文原文You are given a 2D integer array intervals, where intervals[i] = [lefti, righti] describes the ith interval starting at lefti and ending at righti (inclusive). The size…
标签详情
堆(优先队列) 分类
原文链接: https://leetcode-cn.com/problems/process-tasks-using-servers 英文原文You are given two 0-indexed integer arrays servers and tasks of lengths n and m respectively. servers[i] is the weight of the ith server, and tasks[j] is the…
原文链接: https://leetcode-cn.com/problems/design-movie-rental-system 英文原文You have a movie renting company consisting of n shops. You want to implement a renting system that supports searching for, booking, and returning movies. The system should also su…
原文链接: https://leetcode-cn.com/problems/the-number-of-the-smallest-unoccupied-chair 英文原文There is a party where n friends numbered from 0 to n - 1 are attending. There is an infinite number of chairs in this party that are numbered from 0 to infinity. …
原文链接: https://leetcode-cn.com/problems/remove-stones-to-minimize-the-total 英文原文You are given a 0-indexed integer array piles, where piles[i] represents the number of stones in the ith pile, and an integer k. You should apply the following operation e…
原文链接: https://leetcode-cn.com/problems/find-the-kth-largest-integer-in-the-array 英文原文You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros. Return the string that represents the kth l…
原文链接: https://leetcode-cn.com/problems/stock-price-fluctuation 英文原文You are given a stream of records about a particular stock. Each record contains a timestamp and the corresponding price of the stock at that timestamp. Unfortunately due to the volat…
原文链接: https://leetcode-cn.com/problems/two-best-non-overlapping-events 英文原文You are given a 0-indexed 2D integer array of events where events[i] = [startTimei, endTimei, valuei]. The ith event starts at startTimei and ends at endTimei, and if you atte…
原文链接: https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof 中文题目输入整数数组 arr ,找出其中最小的 k 个数。例如,输入4、5、1、6、2、7、3、8这8个数字,则最小的4个数字是1、2、3、4。 示例 1: 输入:arr = [3,2,1], k = 2 输出:[1,2] 或者 [2,1] 示例 2: 输入:arr = [0,1,2,1], k = 1 输出:[0] 限制: 0 <= k <= arr.length <…
原文链接: https://leetcode-cn.com/problems/chou-shu-lcof 中文题目我们把只包含质因子 2、3 和 5 的数称作丑数(Ugly Number)。求按从小到大的顺序的第 n 个丑数。 示例: 输入: n = 10 输出: 12 解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 是前 10 个丑数。 说明: 1 是丑数。 n 不超过1690。 注意:本题与主站 264 题相同:https://leetcode-cn.com/probl…
原文链接: https://leetcode-cn.com/problems/smallest-k-lcci 英文原文Design an algorithm to find the smallest K numbers in an array. Example: Input: arr = [1,3,5,7,2,4,6,8], k = 4 Output: [1,2,3,4] Note: 0 <= len(arr) <= 100000 0 <= k <= min(100000, len(arr)) …
原文链接: https://leetcode-cn.com/problems/continuous-median-lcci 英文原文Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated. Median is the middle value in an ordered integ…
原文链接: https://leetcode-cn.com/problems/get-kth-magic-number-lcci 英文原文Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7. Note that 3, 5, and 7 do not have to be factors, but it should not have any other prime …
原文链接: https://leetcode-cn.com/problems/5TxKeK 英文原文 中文题目小扣在秋日市集入口处发现了一个数字游戏。主办方共有 `N` 个计数器,计数器编号为 `0 ~ N-1`。每个计数器上分别显示了一个数字,小扣按计数器编号升序将所显示的数字记于数组 `nums`。每个计数器上有两个按钮,分别可以实现将显示数字加一或减一。小扣每一次操作可以选择一个计数器,按下加一或减一按钮。 主办方请小扣回答出一个长度为 N 的数组,第 i 个元素(0 <= i …
原文链接: https://leetcode-cn.com/problems/t3fKg1 英文原文 中文题目某实验室计算机待处理任务以 `[start,end,period]` 格式记于二维数组 `tasks`,表示完成该任务的时间范围为起始时间 `start` 至结束时间 `end` 之间,需要计算机投入 `period` 的时长,注意: 1. `period` 可为不连续时间 2. 首尾时间均包含在内 处于开机状态的计算机可同时处理任意多个任务,请返回电脑最少开机多久,可处理完所有任务。 …
原文链接: https://leetcode-cn.com/problems/DFPeFJ 英文原文 中文题目小明的电动车电量充满时可行驶距离为 `cnt`,每行驶 1 单位距离消耗 1 单位电量,且花费 1 单位时间。小明想选择电动车作为代步工具。地图上共有 N 个景点,景点编号为 0 ~ N-1。他将地图信息以 `[城市 A 编号,城市 B 编号,两城市间距离]` 格式整理在在二维数组 `paths`,表示城市 A、B 间存在双向通路。初始状态,电动车电量为 0。每个城市都设有充电桩,`ch…
原文链接: https://leetcode-cn.com/problems/o8SXZn 英文原文 中文题目给定 N 个无限容量且初始均空的水缸,每个水缸配有一个水桶用来打水,第 `i` 个水缸配备的水桶容量记作 `bucket[i]`。小扣有以下两种操作: - 升级水桶:选择任意一个水桶,使其容量增加为 `bucket[i]+1` - 蓄水:将全部水桶接满水,倒入各自对应的水缸 每个水缸对应最低蓄水量记作 vat[i],返回小扣至少需要多少次操作可以完成所有水缸蓄水要求。 注意:实际蓄水量 …
原文链接: https://leetcode-cn.com/problems/jBjn9C 中文题目设计一个找到数据流中第 k 大元素的类(class)。注意是排序后的第 k 大元素,不是第 k 个不同的元素。 请实现 KthLargest 类: KthLargest(int k, int[] nums) 使用整数 k 和整数流 nums 初始化对象。 int add(int val) 将 val 插入数据流 nums 后,返回当前数据流中第 k 大的元素。 示例: 输入: ["KthLarge…
原文链接: https://leetcode-cn.com/problems/g5c51o 中文题目给定一个整数数组 nums 和一个整数 k ,请返回其中出现频率前 k 高的元素。可以按 任意顺序 返回答案。 示例 1: 输入: nums = [1,1,1,2,2,3], k = 2 输出: [1,2] 示例 2: 输入: nums = [1], k = 1 输出: [1] 提示: 1 <= nums.length <= 105 k 的取值范围是 [1, 数组中不相同的元素的个数] 题目数据保…
原文链接: https://leetcode-cn.com/problems/qn8gGX 中文题目给定两个以升序排列的整数数组 nums1 和 nums2 , 以及一个整数 k 。 定义一对值 (u,v),其中第一个元素来自 nums1,第二个元素来自 nums2 。 请找到和最小的 k 个数对 (u1,v1), (u2,v2) ... (uk,vk) 。 示例 1: 输入: nums1 = [1,7,11], nums2 = [2,4,6], k = 3 输出: [1,2],[1,4],[1…
原文链接: https://leetcode-cn.com/problems/xx4gT2 中文题目给定整数数组 nums 和整数 k,请返回数组中第 k 个最大的元素。 请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素。 示例 1: 输入: [3,2,1,5,6,4] 和 k = 2 输出: 5 示例 2: 输入: [3,2,3,1,2,4,5,5,6] 和 k = 4 输出: 4 提示: 1 <= k <= nums.length <= 104 -104 <=…
原文链接: https://leetcode-cn.com/problems/vvXgSW 中文题目给定一个链表数组,每个链表都已经按升序排列。 请将所有链表合并到一个升序链表中,返回合并后的链表。 示例 1: 输入:lists = [[1,4,5],[1,3,4],[2,6]] 输出:[1,1,2,3,4,4,5,6] 解释:链表数组如下: [ 1->4->5, 1->3->4, 2->6 ] 将它们合并到一个有序链表中得到。 1->1->2->3->4->4->5->6 示例 2: 输入:l…
上一页
3 / 3