原文链接: https://leetcode-cn.com/problems/random-pick-with-blacklist 英文原文You are given an integer n and an array of unique integers blacklist. Design an algorithm to pick a random integer in the range [0, n - 1] that is not in blacklist. Any integer tha…
标签详情
排序 分类
原文链接: https://leetcode-cn.com/problems/advantage-shuffle 英文原文You are given two integer arrays nums1 and nums2 both of the same length. The advantage of nums1 with respect to nums2 is the number of indices i for which nums1[i] > nums2[i]. Return any p…
原文链接: https://leetcode-cn.com/problems/reordered-power-of-2 英文原文You are given an integer n. We reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this so that t…
原文链接: https://leetcode-cn.com/problems/boats-to-save-people 英文原文You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at m…
原文链接: https://leetcode-cn.com/problems/fair-candy-swap 英文原文Alice and Bob have a different total number of candies. You are given two integer arrays aliceSizes and bobSizes where aliceSizes[i] is the number of candies of the ith box of candy that Alic…
原文链接: https://leetcode-cn.com/problems/sum-of-subsequence-widths 英文原文The width of a sequence is the difference between the maximum and minimum elements in the sequence. Given an array of integers nums, return the sum of the widths of all the non-empt…
原文链接: https://leetcode-cn.com/problems/orderly-queue 英文原文You are given a string s and an integer k. You can choose one of the first k letters of s and append it at the end of the string.. Return the lexicographically smallest string you could have af…
原文链接: https://leetcode-cn.com/problems/sort-array-by-parity 英文原文Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers. Return any array that satisfies this condition. Example 1: Input: …
原文链接: https://leetcode-cn.com/problems/smallest-range-ii 英文原文You are given an integer array nums and an integer k. For each index i where 0 <= i < nums.length, change nums[i] to be either nums[i] + k or nums[i] - k. The score of nums is the differenc…
原文链接: https://leetcode-cn.com/problems/sort-an-array 英文原文Given an array of integers nums, sort the array in ascending order. Example 1: Input: nums = [5,2,3,1] Output: [1,2,3,5] Example 2: Input: nums = [5,1,1,2,0,0] Output: [0,0,1,1,2,5] Constraints…
原文链接: https://leetcode-cn.com/problems/sort-array-by-parity-ii 英文原文Given an array of integers nums, half of the integers in nums are odd, and the other half are even. Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is e…
原文链接: https://leetcode-cn.com/problems/3sum-with-multiplicity 英文原文Given an integer array arr, and an integer target, return the number of tuples i, j, k such that i < j < k and arr[i] + arr[j] + arr[k] == target. As the answer can be very large, retu…
原文链接: https://leetcode-cn.com/problems/reorder-data-in-log-files 英文原文You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier. There are two types of logs: Letter-logs: All words (except th…
原文链接: https://leetcode-cn.com/problems/minimum-area-rectangle 英文原文You are given an array of points in the X-Y plane points where points[i] = [xi, yi]. Return the minimum area of a rectangle formed from these points, with sides parallel to the X and Y…
原文链接: https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique 英文原文You are given an integer array nums. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1. Return the minimum number of moves to m…
原文链接: https://leetcode-cn.com/problems/bag-of-tokens 英文原文You have an initial power of power, an initial score of 0, and a bag of tokens where tokens[i] is the value of the ith token (0-indexed). Your goal is to maximize your total score by potentiall…
原文链接: https://leetcode-cn.com/problems/reveal-cards-in-increasing-order 英文原文You are given an integer array deck. There is a deck of cards where every card has a unique integer. The integer on the ith card is deck[i]. You can order the deck in any ord…
原文链接: https://leetcode-cn.com/problems/array-of-doubled-pairs 英文原文Given an integer array of even length arr, return true if it is possible to reorder arr such that arr[2 * i + 1] = 2 * arr[2 * i] for every 0 <= i < len(arr) / 2, or false otherwise. E…
原文链接: https://leetcode-cn.com/problems/pancake-sorting 英文原文Given an array of integers arr, sort the array by performing a series of pancake flips. In one pancake flip we do the following steps: Choose an integer k where 1 <= k <= arr.length. Reverse …
原文链接: https://leetcode-cn.com/problems/k-closest-points-to-origin 英文原文Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0). The distance between two…
原文链接: https://leetcode-cn.com/problems/largest-perimeter-triangle 英文原文Given an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a non-…
原文链接: https://leetcode-cn.com/problems/squares-of-a-sorted-array 英文原文Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Example 1: Input: nums = [-4,-1,0,3,10] Out…
原文链接: https://leetcode-cn.com/problems/matrix-cells-in-distance-order 英文原文You are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCenter). Return the coordinat…
原文链接: https://leetcode-cn.com/problems/two-city-scheduling 英文原文A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the it…
原文链接: https://leetcode-cn.com/problems/moving-stones-until-consecutive-ii 英文原文There are some stones in different positions on the X-axis. You are given an integer array stones, the positions of the stones. Call a stone an endpoint stone if it has the…
原文链接: https://leetcode-cn.com/problems/distant-barcodes 英文原文In a warehouse, there is a row of barcodes, where the ith barcode is barcodes[i]. Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guar…
原文链接: https://leetcode-cn.com/problems/largest-values-from-labels 英文原文There is a set of n items. You are given two integer arrays values and labels where the value and the label of the ith element are values[i] and labels[i] respectively. You are als…
原文链接: https://leetcode-cn.com/problems/car-pooling 英文原文There is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west). You are given the integer capacity and an array trips where trip[i] = [numPass…
原文链接: https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements 英文原文Given an integer array arr, return the mean of the remaining integers after removing the smallest 5% and the largest 5% of the elements. Answers within 10-5 of the …
原文链接: https://leetcode-cn.com/problems/relative-sort-array 英文原文Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1. Sort the elements of arr1 such that the relative ordering of items in arr1 ar…