原文链接: https://leetcode-cn.com/problems/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls 英文原文Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i. A…
标签详情
动态规划 分类
原文链接: https://leetcode-cn.com/problems/paint-house-iii 英文原文There is a row of m houses in a small city, each house must be painted with one of the n colors (labeled from 1 to n), some houses that have been painted last summer should not be painted aga…
原文链接: https://leetcode-cn.com/problems/longest-subarray-of-1s-after-deleting-one-element 英文原文Given a binary array nums, you should delete one element from it. Return the size of the longest non-empty subarray containing only 1's in the resulting arra…
原文链接: https://leetcode-cn.com/problems/parallel-courses-ii 英文原文You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCoursei, nextCoursei], representi…
原文链接: https://leetcode-cn.com/problems/stone-game-iv 英文原文Alice and Bob take turns playing a game, with Alice starting first. Initially, there are n stones in a pile. On each player's turn, that player makes a move consisting of removing any non-zero …
原文链接: https://leetcode-cn.com/problems/count-submatrices-with-all-ones 英文原文Given an m x n binary matrix mat, return the number of submatrices that have all ones. Example 1: Input: mat = [[1,0,1],[1,1,0],[1,1,0]] Output: 13 Explanation: There are 6 re…
原文链接: https://leetcode-cn.com/problems/number-of-sub-arrays-with-odd-sum 英文原文Given an array of integers arr, return the number of subarrays with an odd sum. Since the answer can be very large, return it modulo 109 + 7. Example 1: Input: arr = [1,3,5]…
原文链接: https://leetcode-cn.com/problems/number-of-good-ways-to-split-a-string 英文原文You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct let…
原文链接: https://leetcode-cn.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array 英文原文Given an array of positive integers target and an array initial of same size with all zeros. Return the minimum number of operations to form a…
原文链接: https://leetcode-cn.com/problems/string-compression-ii 英文原文Run-length encoding is a string compression method that works by replacing consecutive identical characters (repeated 2 or more times) with the concatenation of the character and the nu…
原文链接: https://leetcode-cn.com/problems/get-the-maximum-score 英文原文You are given two sorted arrays of distinct integers nums1 and nums2. A valid path is defined as follows: Choose array nums1 or nums2 to traverse (from index-0). Traverse the current ar…
原文链接: https://leetcode-cn.com/problems/minimum-cost-to-cut-a-stick 英文原文Given a wooden stick of length n units. The stick is labelled from 0 to n. For example, a stick of length 6 is labelled as follows: Given an integer array cuts where cuts[i] denot…
原文链接: https://leetcode-cn.com/problems/minimum-number-of-days-to-eat-n-oranges 英文原文There are n oranges in the kitchen and you decided to eat some of these oranges every day as follows: Eat one orange. If the number of remaining oranges n is divisible…
原文链接: https://leetcode-cn.com/problems/count-all-possible-routes 英文原文You are given an array of distinct positive integers locations where locations[i] represents the position of city i. You are also given integers start, finish and fuel representing …
原文链接: https://leetcode-cn.com/problems/stone-game-v 英文原文There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue. In each round of the game, Alice divides the row into two no…
原文链接: https://leetcode-cn.com/problems/maximum-length-of-subarray-with-positive-product 英文原文Given an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive. A subarray of an array is a consecut…
原文链接: https://leetcode-cn.com/problems/number-of-ways-to-reorder-array-to-get-same-bst 英文原文Given an array nums that represents a permutation of integers from 1 to n. We are going to construct a binary search tree (BST) by inserting the elements of nu…
原文链接: https://leetcode-cn.com/problems/minimum-deletion-cost-to-avoid-repeating-letters 英文原文Given a string s and an array of integers cost where cost[i] is the cost of deleting the ith character in s. Return the minimum cost of deletions such that th…
原文链接: https://leetcode-cn.com/problems/minimum-cost-to-connect-two-groups-of-points 英文原文You are given two groups of points where the first group has size1 points, the second group has size2 points, and size1 >= size2. The cost of the connection betwe…
原文链接: https://leetcode-cn.com/problems/number-of-sets-of-k-non-overlapping-line-segments 英文原文Given n points on a 1-D plane, where the ith point (from 0 to n-1) is at x = i, find the number of ways we can draw exactly k non-overlapping line segments s…
原文链接: https://leetcode-cn.com/problems/minimum-one-bit-operations-to-make-integers-zero 英文原文Given an integer n, you must transform it into 0 using the following operations any number of times: Change the rightmost (0th) bit in the binary representati…
原文链接: https://leetcode-cn.com/problems/count-subtrees-with-max-distance-between-cities 英文原文There are n cities numbered from 1 to n. You are given an array edges of size n-1, where edges[i] = [ui, vi] represents a bidirectional edge between cities ui …
原文链接: https://leetcode-cn.com/problems/count-substrings-that-differ-by-one-character 英文原文Given two strings s and t, find the number of ways you can choose a non-empty substring of s and replace a single character by a different character such that th…
原文链接: https://leetcode-cn.com/problems/number-of-ways-to-form-a-target-string-given-a-dictionary 英文原文You are given a list of strings of the same length words and a string target. Your task is to form target using the given words under the following r…
原文链接: https://leetcode-cn.com/problems/best-team-with-no-conflicts 英文原文You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of al…
原文链接: https://leetcode-cn.com/problems/minimum-deletions-to-make-string-balanced 英文原文You are given a string s consisting only of characters 'a' and 'b'. You can delete any number of characters in s to make s balanced. s is balanced if there is no…
原文链接: https://leetcode-cn.com/problems/minimum-jumps-to-reach-home 英文原文A certain bug's home is on the x-axis at position x. Help them get there from position 0. The bug jumps according to the following rules: It can jump exactly a positions forward (…
原文链接: https://leetcode-cn.com/problems/distribute-repeating-integers 英文原文You are given an array of n integers, nums, where there are at most 50 unique values in the array. You are also given an array of m customer order quantities, quantity, where qu…
原文链接: https://leetcode-cn.com/problems/minimum-number-of-removals-to-make-mountain-array 英文原文You may recall that an array arr is a mountain array if and only if: arr.length >= 3 There exists some index i (0-indexed) with 0 < i < arr.length - 1 such t…
原文链接: https://leetcode-cn.com/problems/get-maximum-in-generated-array 英文原文You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated in the following way: nums[0] = 0 nums[1] = 1 nums[2 * i] = nums[i] when 2 <= 2 * i <= n…