原文链接: https://leetcode-cn.com/problems/car-fleet 英文原文There are n cars going to the same destination along a one-lane road. The destination is target miles away. You are given two integer array position and speed, both of length n, where position[i] i…
分类详情
中等 分类
原文链接: https://leetcode-cn.com/problems/exam-room 英文原文There is an exam room with n seats in a single row labeled from 0 to n - 1. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are…
原文链接: https://leetcode-cn.com/problems/score-of-parentheses 英文原文Given a balanced parentheses string s, return the score of the string. The score of a balanced parentheses string is based on the following rule: "()" has score 1. AB has score A + B, wh…
原文链接: https://leetcode-cn.com/problems/mirror-reflection 英文原文There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered 0, 1, and 2. The squar…
原文链接: https://leetcode-cn.com/problems/score-after-flipping-matrix 英文原文You are given an m x n binary matrix grid. A move consists of choosing any row or column and toggling each value in that row or column (i.e., changing all 0's to 1's, and all 1's …
原文链接: https://leetcode-cn.com/problems/all-nodes-distance-k-in-binary-tree 英文原文Given the root of a binary tree, the value of a target node target, and an integer k, return an array of the values of all nodes that have a distance k from the target nod…
原文链接: https://leetcode-cn.com/problems/smallest-subtree-with-all-the-deepest-nodes 英文原文Given the root of a binary tree, the depth of each node is the shortest distance to the root. Return the smallest subtree such that it contains all the deepest nod…
原文链接: https://leetcode-cn.com/problems/prime-palindrome 英文原文Given an integer n, return the smallest prime palindrome greater than or equal to n. An integer is prime if it has exactly two divisors: 1 and itself. Note that 1 is not a prime number. For …
原文链接: 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/length-of-longest-fibonacci-subsequence 英文原文A sequence x1, x2, ..., xn is Fibonacci-like if: n >= 3 xi + xi+1 == xi+2 for all i + 2 <= n Given a strictly increasing array arr of positive integers forming a seque…
原文链接: https://leetcode-cn.com/problems/walking-robot-simulation 英文原文A robot on an infinite XY-plane starts at point (0, 0) facing north. The robot can receive a sequence of these three possible types of commands: -2: Turn left 90 degrees. -1: Turn ri…
原文链接: 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/stone-game 英文原文Alice and Bob play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game is to…
原文链接: 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/random-flip-matrix 英文原文There is an m x n binary grid matrix with all the values set 0 initially. Design an algorithm to randomly pick an index (i, j) where matrix[i][j] == 0 and flips it to 1. All the indices (i…
原文链接: https://leetcode-cn.com/problems/loud-and-rich 英文原文There is a group of n people labeled from 0 to n - 1 where each person has a different amount of money and a different level of quietness. You are given an array richer where richer[i] = [ai, b…
原文链接: https://leetcode-cn.com/problems/implement-rand10-using-rand7 英文原文Given the API rand7() that generates a uniform random integer in the range [1, 7], write a function rand10() that generates a uniform random integer in the range [1, 10]. You can…
原文链接: 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/generate-random-point-in-a-circle 英文原文Given the radius and the position of the center of a circle, implement the function randPoint which generates a uniform random point inside the circle. Implement the Solutio…
原文链接: https://leetcode-cn.com/problems/decoded-string-at-index 英文原文You are given an encoded string s. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken: If the character read is a let…
原文链接: 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/possible-bipartition 英文原文We want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not go into the same group. Given the i…
原文链接: https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal 英文原文Given two integer arrays, preorder and postorder where preorder is the preorder traversal of a binary tree of distinct values and postorder is the …
原文链接: https://leetcode-cn.com/problems/find-and-replace-pattern 英文原文Given a list of strings words and a string pattern, return a list of words[i] that match pattern. You may return the answer in any order. A word matches the pattern if there exists a…
原文链接: https://leetcode-cn.com/problems/groups-of-special-equivalent-strings 英文原文You are given an array of strings of the same length words. In one move, you can swap any two even indexed characters or any two odd indexed characters of a string words[…
原文链接: https://leetcode-cn.com/problems/all-possible-full-binary-trees 英文原文Given an integer n, return a list of all possible full binary trees with n nodes. Each node of each tree in the answer must have Node.val == 0. Each element of the answer is th…
原文链接: https://leetcode-cn.com/problems/bitwise-ors-of-subarrays 英文原文We have an array arr of non-negative integers. For every (contiguous) subarray sub = [arr[i], arr[i + 1], ..., arr[j]] (with i <= j), we take the bitwise OR of all the elements in su…
原文链接: https://leetcode-cn.com/problems/rle-iterator 英文原文We can use run-length encoding (i.e., RLE) to encode a sequence of integers. In a run-length encoded array of even length encoding (0-indexed), for all even i, encoding[i] tells us the number of…
原文链接: https://leetcode-cn.com/problems/online-stock-span 英文原文Design an algorithm that collects daily price quotes for some stock and returns the span of that stock's price for the current day. The span of the stock's price today is defined as the max…