原文链接: https://leetcode-cn.com/problems/strange-printer 英文原文There is a strange printer with the following two special properties: The printer can only print a sequence of the same character each time. At each turn, the printer can print new characters…
标签详情
动态规划 分类
原文链接: https://leetcode-cn.com/problems/number-of-longest-increasing-subsequence 英文原文Given an integer array nums, return the number of longest increasing subsequences. Notice that the sequence has to be strictly increasing. Example 1: Input: nums = [1…
原文链接: 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/knight-probability-in-chessboard 英文原文On an n x n chessboard, a knight starts at the cell (row, column) and attempts to make exactly k moves. The rows and columns are 0-indexed, so the top-left cell is (0, 0), an…
原文链接: https://leetcode-cn.com/problems/maximum-sum-of-3-non-overlapping-subarrays 英文原文Given an integer array nums and an integer k, find three non-overlapping subarrays of length k with maximum sum and return them. Return the result as a list of indi…
原文链接: https://leetcode-cn.com/problems/stickers-to-spell-word 英文原文We are given n different types of stickers. Each sticker has a lowercase English word on it. You would like to spell out the given string target by cutting individual letters from your…
原文链接: https://leetcode-cn.com/problems/partition-to-k-equal-sum-subsets 英文原文Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal. Example 1: Input: nums = […
原文链接: https://leetcode-cn.com/problems/minimum-ascii-delete-sum-for-two-strings 英文原文Given two strings s1 and s2, return the lowest ASCII sum of deleted characters to make two strings equal. Example 1: Input: s1 = "sea", s2 = "eat" Output: 231 Explana…
原文链接: 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/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/count-different-palindromic-subsequences 英文原文Given a string s, return the number of different non-empty palindromic subsequences in s. Since the answer may be very large, return it modulo 109 + 7. A subsequence …
原文链接: https://leetcode-cn.com/problems/cherry-pickup 英文原文You are given an n x n grid representing a field of cherries, each cell is one of three possible integers. 0 means the cell is empty, so you can pass through, 1 means the cell contains a cherry…
原文链接: https://leetcode-cn.com/problems/delete-and-earn 英文原文You are given an integer array nums. You want to maximize the number of points you get by performing the following operation any number of times: Pick any nums[i] and delete it to earn nums[i…
原文链接: https://leetcode-cn.com/problems/min-cost-climbing-stairs 英文原文You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps. You can either start from the …
原文链接: https://leetcode-cn.com/problems/largest-plus-sign 英文原文You are given an integer n. You have an n x n binary grid grid with all values initially 1's except for some indices given in the array mines. The ith element of the array mines is defined …
原文链接: https://leetcode-cn.com/problems/cheapest-flights-within-k-stops 英文原文There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is a flight from city fromi…
原文链接: https://leetcode-cn.com/problems/rotated-digits 英文原文An integer x is a good if after rotating each digit individually by 180 degrees, we get a valid number that is different from x. Each digit must be rotated - we cannot choose to leave it alone…
原文链接: https://leetcode-cn.com/problems/domino-and-tromino-tiling 英文原文You have two types of tiles: a 2 x 1 domino shape and a tromino shape. You may rotate these shapes. Given an integer n, return the number of ways to tile an 2 x n board. Since the a…
原文链接: https://leetcode-cn.com/problems/champagne-tower 英文原文We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row. Each glass holds one cup of champagne. Then, some champagne is pou…
原文链接: https://leetcode-cn.com/problems/split-array-with-same-average 英文原文You are given an integer array nums. You should move each element of nums into one of the two arrays A and B such that A and B are non-empty, and average(A) == average(B). Retur…
原文链接: https://leetcode-cn.com/problems/soup-servings 英文原文There are two types of soup: type A and type B. Initially, we have n ml of each type of soup. There are four kinds of operations: Serve 100 ml of soup A and 0 ml of soup B, Serve 75 ml of soup …
原文链接: https://leetcode-cn.com/problems/largest-sum-of-averages 英文原文You are given an integer array nums and an integer k. You can partition the array into at most k non-empty adjacent subarrays. The score of a partition is the sum of the averages of e…
原文链接: https://leetcode-cn.com/problems/race-car 英文原文Your car starts at position 0 and speed +1 on an infinite number line. Your car can go into negative positions. Your car drives automatically according to a sequence of instructions 'A' (accelerate)…
原文链接: https://leetcode-cn.com/problems/binary-trees-with-factors 英文原文Given an array of unique integers, arr, where each integer arr[i] is strictly greater than 1. We make a binary tree using these integers, and each number may be used for any number …
原文链接: https://leetcode-cn.com/problems/count-unique-characters-of-all-substrings-of-a-given-string 英文原文Let's define a function countUniqueChars(s) that returns the number of unique characters on s. For example if s = "LEETCODE" then "L", "T", "C", "O…
原文链接: https://leetcode-cn.com/problems/sum-of-distances-in-tree 英文原文There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given the integer n and the array edges where edges[i] = [ai, bi] indicates that t…
原文链接: https://leetcode-cn.com/problems/new-21-game 英文原文Alice plays the following game, loosely based on the card game "21". Alice starts with 0 points and draws numbers while she has less than k points. During each draw, she gains an integer number o…
原文链接: https://leetcode-cn.com/problems/push-dominoes 英文原文There are n dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right. After each second,…
原文链接: https://leetcode-cn.com/problems/longest-mountain-in-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 that: arr[0] < arr[1] < .…
原文链接: https://leetcode-cn.com/problems/shortest-path-visiting-all-nodes 英文原文You have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an…