原文链接: https://leetcode-cn.com/problems/132-pattern 英文原文Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j]. Return true if there is a 132…
标签详情
二分查找 分类
原文链接: https://leetcode-cn.com/problems/smallest-good-base 英文原文Given an integer n represented as a string, return the smallest good base of n. We call k >= 2 a good base of n, if all digits of n base k are 1's. Example 1: Input: n = "13" Output: "3" E…
原文链接: https://leetcode-cn.com/problems/reverse-pairs 英文原文Given an integer array nums, return the number of reverse pairs in the array. A reverse pair is a pair (i, j) where 0 <= i < j < nums.length and nums[i] > 2 * nums[j]. Example 1: Input: nums = …
原文链接: https://leetcode-cn.com/problems/single-element-in-a-sorted-array 英文原文You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Return the single eleme…
原文链接: https://leetcode-cn.com/problems/valid-triangle-number 英文原文Given an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle. Example 1: Input: nums = [2,2,3,4…
原文链接: https://leetcode-cn.com/problems/sum-of-square-numbers 英文原文Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Input: c = 5 Output: true Explanation: 1 * 1 + 2 * 2 = 5 Example 2: Input:…
原文链接: https://leetcode-cn.com/problems/find-k-closest-elements 英文原文Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order. An integer a is closer to…
原文链接: https://leetcode-cn.com/problems/kth-smallest-number-in-multiplication-table 英文原文Nearly everyone has used the Multiplication Table. The multiplication table of size m x n is an integer matrix mat where mat[i][j] == i * j (1-indexed). Given thre…
原文链接: https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray 英文原文Given two integer arrays nums1 and nums2, return the maximum length of a subarray that appears in both arrays. Example 1: Input: nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7] O…
原文链接: https://leetcode-cn.com/problems/find-k-th-smallest-pair-distance 英文原文The distance of a pair of integers a and b is defined as the absolute difference between a and b. Given an integer array nums and an integer k, return the kth smallest distan…
原文链接: https://leetcode-cn.com/problems/find-smallest-letter-greater-than-target 英文原文Given a characters array letters that is sorted in non-decreasing order and a character target, return the smallest character in the array that is larger than target.…
原文链接: https://leetcode-cn.com/problems/reach-a-number 英文原文You are standing at position 0 on an infinite number line. There is a destination at position target. You can make some number of moves numMoves so that: On each move, you can either go left o…
原文链接: https://leetcode-cn.com/problems/binary-search 英文原文Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return …
原文链接: https://leetcode-cn.com/problems/swim-in-rising-water 英文原文You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j). The rain starts to fall. At time t, the depth of the water everywher…
原文链接: https://leetcode-cn.com/problems/k-th-smallest-prime-fraction 英文原文You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k. For every i and j where 0 <= i…
原文链接: https://leetcode-cn.com/problems/preimage-size-of-factorial-zeroes-function 英文原文Let f(x) be the number of zeroes at the end of x!. Recall that x! = 1 * 2 * 3 * ... * x and by convention, 0! = 1. For example, f(3) = 0 because 3! = 6 has no zeroe…
原文链接: https://leetcode-cn.com/problems/friends-of-appropriate-ages 英文原文There are n persons on a social media website. You are given an integer array ages where ages[i] is the age of the ith person. A Person x will not send a friend request to a perso…
原文链接: https://leetcode-cn.com/problems/most-profit-assigning-work 英文原文You have n jobs and m workers. You are given three arrays: difficulty, profit, and worker where: difficulty[i] and profit[i] are the difficulty and the profit of the ith job, and w…
原文链接: https://leetcode-cn.com/problems/peak-index-in-a-mountain-array 英文原文Let's call an array arr a mountain if the following properties hold: arr.length >= 3 There exists some i with 0 < i < arr.length - 1 such that: arr[0] < arr[1] < ... arr[i-1] <…
原文链接: 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/koko-eating-bananas 英文原文Koko loves to eat bananas. There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours. Koko can decide her bananas-per-hour eating…
原文链接: https://leetcode-cn.com/problems/nth-magical-number 英文原文A positive integer is magical if it is divisible by either a or b. Given the three integers n, a, and b, return the nth magical number. Since the answer may be very large, return it modulo…
原文链接: https://leetcode-cn.com/problems/random-pick-with-weight 英文原文You are given a 0-indexed array of positive integers w where w[i] describes the weight of the ith index. You need to implement the function pickIndex(), which randomly picks an index …
原文链接: https://leetcode-cn.com/problems/shortest-subarray-with-sum-at-least-k 英文原文Given an integer array nums and an integer k, return the length of the shortest non-empty subarray of nums with a sum of at least k. If there is no such subarray, return…
原文链接: https://leetcode-cn.com/problems/random-point-in-non-overlapping-rectangles 英文原文You are given an array of non-overlapping axis-aligned rectangles rects where rects[i] = [ai, bi, xi, yi] indicates that (ai, bi) is the bottom-left corner point of…
原文链接: https://leetcode-cn.com/problems/super-egg-drop 英文原文You are given k identical eggs and you have access to a building with n floors labeled from 1 to n. You know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor …
原文链接: 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/numbers-at-most-n-given-digit-set 英文原文Given an array of digits which is sorted in non-decreasing order. You can write numbers using each digits[i] as many times as we want. For example, if digits = ['1','3','5']…
原文链接: https://leetcode-cn.com/problems/online-election 英文原文You are given two integer arrays persons and times. In an election, the ith vote was cast for persons[i] at time times[i]. For each query at a time t, find the person that was leading the ele…
原文链接: https://leetcode-cn.com/problems/time-based-key-value-store 英文原文Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key's value at a certain timestamp. Implement…