原文链接: https://leetcode-cn.com/problems/maximize-grid-happiness 英文原文You are given four integers, m, n, introvertsCount, and extrovertsCount. You have an m x n grid, and there are two types of people: introverts and extroverts. There are introvertsCoun…
标签详情
动态规划 分类
原文链接: https://leetcode-cn.com/problems/largest-color-value-in-a-directed-graph 英文原文There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1. You are given a string colors where colors[i] is a lowercase English …
原文链接: https://leetcode-cn.com/problems/minimum-xor-sum-of-two-arrays 英文原文You are given two integer arrays nums1 and nums2 of length n. The XOR sum of the two integer arrays is (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XO…
原文链接: https://leetcode-cn.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible 英文原文There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k sticks are visible from t…
原文链接: https://leetcode-cn.com/problems/stone-game-viii 英文原文Alice and Bob take turns playing a game, with Alice starting first. There are n stones arranged in a row. On each player's turn, while the number of stones is more than one, they will do the …
原文链接: https://leetcode-cn.com/problems/minimum-cost-to-change-the-final-value-of-expression 英文原文You are given a valid boolean expression as a string expression consisting of the characters '1','0','&' (bitwise AND operator),'|' (bitwise OR operator),…
原文链接: https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum 英文原文The alternating sum of a 0-indexed array is defined as the sum of the elements at even indices minus the sum of the elements at odd indices. For example, the alternating s…
原文链接: https://leetcode-cn.com/problems/the-earliest-and-latest-rounds-where-players-compete 英文原文There is a tournament where n players are participating. The players are standing in a single row and are numbered from 1 to n based on their initial stan…
原文链接: https://leetcode-cn.com/problems/egg-drop-with-2-eggs-and-n-floors 英文原文You are given two 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 eg…
原文链接: https://leetcode-cn.com/problems/minimum-cost-to-reach-destination-in-time 英文原文There is a country of n cities numbered from 0 to n - 1 where all the cities are connected by bi-directional roads. The roads are represented as a 2D integer array e…
原文链接: https://leetcode-cn.com/problems/painting-a-grid-with-three-different-colors 英文原文You are given two integers m and n. Consider an m x n grid where each cell is initially white. You can paint each cell red, green, or blue. All cells must be paint…
原文链接: https://leetcode-cn.com/problems/maximum-compatibility-score-sum 英文原文There is a survey that consists of n questions where each question's answer is either 0 (no) or 1 (yes). The survey was given to m students numbered from 0 to m - 1 and m ment…
原文链接: https://leetcode-cn.com/problems/count-number-of-special-subsequences 英文原文A sequence is special if it consists of a positive number of 0s, followed by a positive number of 1s, then a positive number of 2s. For example, [0,1,2] and [0,0,1,1,1,2]…
原文链接: https://leetcode-cn.com/problems/number-of-ways-to-arrive-at-destination 英文原文You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections. The inputs are generated such that yo…
原文链接: https://leetcode-cn.com/problems/number-of-ways-to-separate-numbers 英文原文You wrote down many positive integers in a string called num. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the l…
原文链接: https://leetcode-cn.com/problems/the-number-of-good-subsets 英文原文You are given an integer array nums. We call a subset of nums good if its product can be represented as a product of one or more distinct prime numbers. For example, if nums = [1, …
原文链接: https://leetcode-cn.com/problems/minimize-the-difference-between-target-and-chosen-elements 英文原文You are given an m x n integer matrix mat and an integer target. Choose one integer from each row in the matrix such that the absolute difference be…
原文链接: https://leetcode-cn.com/problems/number-of-unique-good-subsequences 英文原文You are given a binary string binary. A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of "0"). Find the number of…
原文链接: https://leetcode-cn.com/problems/maximum-earnings-from-taxi 英文原文There are n points on a road you are driving your taxi on. The n points on the road are labeled from 1 to n in the direction you are going, and you want to drive from point 1 to po…
原文链接: https://leetcode-cn.com/problems/first-day-where-you-have-been-in-all-the-rooms 英文原文There are n rooms you need to visit, labeled from 0 to n - 1. Each day is labeled, starting from 0. You will go in and visit one room a day. Initially on day 0,…
原文链接: https://leetcode-cn.com/problems/maximum-product-of-the-length-of-two-palindromic-subsequences 英文原文Given a string s, find two disjoint palindromic subsequences of s such that the product of their lengths is maximized. The two subsequences are d…
原文链接: https://leetcode-cn.com/problems/smallest-missing-genetic-value-in-each-subtree 英文原文There is a family tree rooted at 0 consisting of n nodes numbered 0 to n - 1. You are given a 0-indexed integer array parents, where parents[i] is the parent fo…
原文链接: https://leetcode-cn.com/problems/partition-array-into-two-arrays-to-minimize-sum-difference 英文原文You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of…
原文链接: 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/parallel-courses-iii 英文原文You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given a 2D integer array relations where relations[j] = [prevCoursej, nextCoursej] …
原文链接: https://leetcode-cn.com/problems/check-if-an-original-string-exists-given-two-encoded-strings 英文原文An original string, consisting of lowercase English letters, can be encoded by the following steps: Arbitrarily split it into a sequence of some n…
原文链接: https://leetcode-cn.com/problems/vowels-of-all-substrings 英文原文Given a string word, return the sum of the number of vowels ('a', 'e', 'i', 'o', and 'u') in every substring of word. A substring is a contiguous (non-empty) sequence of characters w…
原文链接: https://leetcode-cn.com/problems/count-fertile-pyramids-in-a-land 英文原文A farmer has a rectangular grid of land with m rows and n columns that can be divided into unit cells. Each cell is either fertile (represented by a 1) or barren (represented…
原文链接: https://leetcode-cn.com/problems/broken-board-dominoes 中文题目你有一块棋盘,棋盘上有一些格子已经坏掉了。你还有无穷块大小为1 * 2的多米诺骨牌,你想把这些骨牌不重叠地覆盖在完好的格子上,请找出你最多能在棋盘上放多少块骨牌?这些骨牌可以横着或者竖着放。 输入:n, m代表棋盘的大小;broken是一个b * 2的二维数组,其中每个元素代表棋盘上每一个坏掉的格子的位置。 输出:一个整数,代表最多能在棋盘上放的骨牌数。 示例 1: …
原文链接: https://leetcode-cn.com/problems/three-steps-problem-lcci 英文原文A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the s…