原文链接: https://leetcode-cn.com/problems/maximum-length-of-pair-chain 英文原文You are given an array of n pairs pairs where pairs[i] = [lefti, righti] and lefti < righti. A pair p2 = [c, d] follows a pair p1 = [a, b] if b < c. A chain of pairs can be forme…
标签详情
贪心 分类
原文链接: https://leetcode-cn.com/problems/split-array-into-consecutive-subsequences 英文原文You are given an integer array nums that is sorted in non-decreasing order. Determine if it is possible to split nums into one or more subsequences such that both of…
原文链接: https://leetcode-cn.com/problems/maximum-swap 英文原文You are given an integer num. You can swap two digits at most once to get the maximum valued number. Return the maximum valued number you can get. Example 1: Input: num = 2736 Output: 7236 Expla…
原文链接: https://leetcode-cn.com/problems/valid-parenthesis-string 英文原文Given a string s containing only three types of characters: '(', ')' and '*', return true if s is valid. The following rules define a valid string: Any left parenthesis '(' must have…
原文链接: https://leetcode-cn.com/problems/valid-palindrome-ii 英文原文Given a string s, return true if the s can be palindrome after deleting at most one character from it. Example 1: Input: s = "aba" Output: true Example 2: Input: s = "abca" Output: true E…
原文链接: https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee 英文原文You are given an array prices where prices[i] is the price of a given stock on the ith day, and an integer fee representing a transaction fee. Find the ma…
原文链接: https://leetcode-cn.com/problems/monotone-increasing-digits 英文原文An integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y. Given an integer n, return the largest number that is less than or equ…
原文链接: https://leetcode-cn.com/problems/set-intersection-size-at-least-two 英文原文An integer interval [a, b] (for integers a < b) is a set of all consecutive integers from a to b, including a and b. Find the minimum size of a set S such that for every in…
原文链接: https://leetcode-cn.com/problems/partition-labels 英文原文You are given a string s. We want to partition the string into as many parts as possible so that each letter appears in at most one part. Return a list of integers representing the size of t…
原文链接: https://leetcode-cn.com/problems/couples-holding-hands 英文原文There are n couples sitting in 2n seats arranged in a row and want to hold hands. The people and seats are represented by an integer array row where row[i] is the ID of the person sitti…
原文链接: https://leetcode-cn.com/problems/reorganize-string 英文原文Given a string s, rearrange the characters of s so that any two adjacent characters are not the same. Return any possible rearrangement of s or return "" if not possible. Example 1: Input: …
原文链接: https://leetcode-cn.com/problems/max-chunks-to-make-sorted-ii 英文原文You are given an integer array arr. We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equa…
原文链接: https://leetcode-cn.com/problems/max-chunks-to-make-sorted 英文原文You are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1]. We split arr into some number of chunks (i.e., partitions), and…
原文链接: https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline 英文原文There is a city composed of n x n blocks, where each block contains a single building shaped like a vertical square prism. You are given a 0-indexed n x n integer matrix gri…
原文链接: 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/hand-of-straights 英文原文Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size groupSize, and consists of groupSize consecutive cards. Given an integer array …
原文链接: https://leetcode-cn.com/problems/minimum-cost-to-hire-k-workers 英文原文There are n workers. You are given two integer arrays quality and wage where quality[i] is the quality of the ith worker and wage[i] is the minimum wage expectation for the ith…
原文链接: https://leetcode-cn.com/problems/lemonade-change 英文原文At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bills). Each customer will only buy one lemo…
原文链接: 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/minimum-number-of-refueling-stops 英文原文A car travels from a starting position to a destination which is target miles east of the starting position. There are gas stations along the way. The gas stations are repre…
原文链接: 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/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/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/minimum-add-to-make-parentheses-valid 英文原文A parentheses string is valid if and only if: It is the empty string, It can be written as AB (A concatenated with B), where A and B are valid strings, or It can be writ…
原文链接: https://leetcode-cn.com/problems/stamping-the-sequence 英文原文You are given two strings stamp and target. Initially, there is a string s of length target.length with all s[i] == '?'. In one turn, you can place stamp over s and replace every letter…
原文链接: https://leetcode-cn.com/problems/di-string-match 英文原文A permutation perm of n + 1 integers of all the integers in the range [0, n] can be represented as a string s of length n where: s[i] == 'I' if perm[i] < perm[i + 1], and s[i] == 'D' if perm[…
原文链接: 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/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/delete-columns-to-make-sorted-ii 英文原文You are given an array of n strings strs, all of the same length. We may choose any deletion indices, and we delete all the characters in those indices for each string. For e…