原文链接: https://leetcode-cn.com/problems/split-two-strings-to-make-palindrome 英文原文You are given two strings a and b of the same length. Choose an index and split both strings at the same index, splitting a into two strings: aprefix and asuffix where a …
标签详情
贪心 分类
原文链接: https://leetcode-cn.com/problems/furthest-building-you-can-reach 英文原文You are given an integer array heights representing the heights of buildings, some bricks, and some ladders. You start your journey from building 0 and move to the next buildi…
原文链接: 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/minimum-deletions-to-make-character-frequencies-unique 英文原文A string s is called good if there are no two different characters in s that have the same frequency. Given a string s, return the minimum number of cha…
原文链接: https://leetcode-cn.com/problems/sell-diminishing-valued-colored-balls 英文原文You have an inventory of different colored balls, and there is a customer that wants orders balls of any color. The customer weirdly values the colored balls. Each color…
原文链接: https://leetcode-cn.com/problems/smallest-string-with-a-given-numeric-value 英文原文The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the …
原文链接: https://leetcode-cn.com/problems/minimum-adjacent-swaps-to-reach-the-kth-smallest-number 英文原文You are given a string num, representing a large integer, and an integer k. We call some integer wonderful if it is a permutation of the digits in num …
原文链接: https://leetcode-cn.com/problems/maximum-distance-between-a-pair-of-values 英文原文You are given two non-increasing 0-indexed integer arrays nums1 and nums2. A pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.lengt…
原文链接: https://leetcode-cn.com/problems/minimize-maximum-pair-sum-in-array 英文原文The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs. For example, if we have pairs (1,5), (2,3), and (4,4), the …
原文链接: https://leetcode-cn.com/problems/minimum-number-of-swaps-to-make-the-binary-string-alternating 英文原文Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible. The string is called alt…
原文链接: https://leetcode-cn.com/problems/maximum-value-after-insertion 英文原文You are given a very large integer n, represented as a string, and an integer digit x. The digits in n and the digit x are in the inclusive range [1, 9], and n may represe…
原文链接: https://leetcode-cn.com/problems/minimum-number-of-flips-to-make-the-binary-string-alternating 英文原文You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence: Type-1: Remove the character a…
原文链接: https://leetcode-cn.com/problems/merge-triplets-to-form-target-triplet 英文原文A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You are also given an int…
原文链接: https://leetcode-cn.com/problems/largest-odd-number-in-string 英文原文You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string "" if no od…
原文链接: https://leetcode-cn.com/problems/sum-game 英文原文Alice and Bob take turns playing a game, with Alice starting first. You are given a string num of even length consisting of digits and '?' characters. On each turn, a player will do the following if…
原文链接: https://leetcode-cn.com/problems/eliminate-maximum-number-of-monsters 英文原文You are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, where dist[i] is the in…
原文链接: https://leetcode-cn.com/problems/largest-number-after-mutating-substring 英文原文You are given a string num, which represents a large integer. You are also given a 0-indexed integer array change of length 10 that maps each digit 0-9 to another digi…
原文链接: https://leetcode-cn.com/problems/maximum-number-of-weeks-for-which-you-can-work 英文原文There are n projects numbered from 0 to n - 1. You are given an integer array milestones where each milestones[i] denotes the number of milestones the ith proje…
原文链接: https://leetcode-cn.com/problems/array-with-elements-not-equal-to-average-of-neighbors 英文原文You are given a 0-indexed array nums of distinct integers. You want to rearrange the elements in the array such that every element in the rearranged arra…
原文链接: https://leetcode-cn.com/problems/minimum-time-to-type-word-using-special-typewriter 英文原文There is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer. A character can only be typed if the pointer is…
原文链接: https://leetcode-cn.com/problems/maximum-matrix-sum 英文原文You are given an n x n integer matrix. You can do the following operation any number of times: Choose any two adjacent elements of matrix and multiply each of them by -1. Two elements are …
原文链接: https://leetcode-cn.com/problems/minimum-number-of-swaps-to-make-the-string-balanced 英文原文You are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'. A string is …
原文链接: https://leetcode-cn.com/problems/minimum-non-zero-product-of-the-array-elements 英文原文You are given a positive integer p. Consider an array nums (1-indexed) that consists of the integers in the inclusive range [1, 2p - 1] in their binary represen…
原文链接: https://leetcode-cn.com/problems/find-original-array-from-doubled-array 英文原文An integer array original is transformed into a doubled array changed by appending twice the value of every element in original, and then randomly shuffling the resulti…
原文链接: https://leetcode-cn.com/problems/the-number-of-weak-characters-in-the-game 英文原文You are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D integer array pr…
原文链接: https://leetcode-cn.com/problems/longest-subsequence-repeated-k-times 英文原文You are given a string s of length n, and an integer k. You are tasked to find the longest subsequence repeated k times in string s. A subsequence is a string that can be…
原文链接: https://leetcode-cn.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color 英文原文There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] …
原文链接: https://leetcode-cn.com/problems/minimum-moves-to-convert-string 英文原文You are given a string s consisting of n characters which are either 'X' or 'O'. A move is defined as selecting three consecutive characters of s and converting them to 'O'. N…
原文链接: https://leetcode-cn.com/problems/stone-game-ix 英文原文Alice and Bob continue their games with stones. There is a row of n stones, and each stone has an associated value. You are given an integer array stones, where stones[i] is the value of the it…
原文链接: https://leetcode-cn.com/problems/smallest-k-length-subsequence-with-occurrences-of-a-letter 英文原文You are given a string s, an integer k, a letter letter, and an integer repetition. Return the lexicographically smallest subsequence of s of length…