<Code author="Calf" />
3297. Count Substrings That Can Be Rearranged to Contain a String I
#Problem You are given two strings word1 and word2. A string x is called valid if x can be rearranged to have word2 as a prefix. A prefix of a string is a substring that starts from the beginning of the string and extends to any point …
3410. Maximize Subarray Sum After Removing All Occurrences of One Element
#Problem You are given an integer array nums. You can do the following operation on the array at most once: Choose any integer x such that nums remains non-empty on removing all occurrences of x. Remove all occurrences of x from the array. …
1186. Maximum Subarray Sum with One Deletion
#Problem Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that …
53. Maximum Subarray
#Problem Given an integer array nums, find the subarray with the largest sum, and return its sum. A subarray is a contiguous non-empty sequence of elements within an array. https://leetcode.com/problems/maximum-subarray/ Example 1: Input: …
3045. Count Prefix and Suffix Pairs II
#Problem 跟 3042. Count Prefix and Suffix Pairs I 一模一样,但单词数量从 50 提升到 10⁵,同时单词的长度也从 10 提升到 10⁵。 https://leetcode.com/problems/count-prefix-and-suffix-pairs-ii/ Constraints: 1 <= words.length <= 10⁵ 1 <= words[i].length <= 10⁵ words[i] …
3042. Count Prefix and Suffix Pairs I
#Problem You are given a 0-indexed string array words. Let’s define a boolean function isPrefixAndSuffix that takes two strings, str1 and str2: isPrefixAndSuffix(str1, str2) returns true if str1 is both a prefix and a suffix of str2, and …
2264. Largest 3-Same-Digit Number in String
#Problem You are given a string num representing a large integer. An integer is good if it meets the following conditions: It is a substring of num with length 3. It consists of only one unique digit. Return the maximum good integer as a …
1408. String Matching in an Array
#Problem Given an array of string words, return all strings in words that is a substring of another word. You can return the answer in any order. A substring is a contiguous sequence of characters within a string. …
3019. Number of Changing Keys
#Problem You are given a 0-indexed string s typed by a user. Changing a key is defined as using a key different from the last used key. For example, s = "ab" has a change of a key while s = "bBBb" does not have any. Return the number of …
1769. Minimum Number of Operations to Move All Balls to Each Box
#Problem You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the iᵗʰ box is empty, and '1' if it contains one ball. In one operation, you can move one ball from a box to an adjacent box. Box i is …
2274. Maximum Consecutive Floors Without Special Floors
#Problem Alice manages a company and has rented some floors of a building as office space. Alice has decided some of these floors should be special floors, used for relaxation only. You are given two integers bottom and top, which denote …
3395. Subsequences with a Unique Middle Mode I
#Problem 唯一中间众数子序列。 Given an integer array nums, find the number of subsequences of size 5 of nums with a unique middle mode. A subsequence is an array that can be derived from another array by deleting some or no elements without changing …
2381. Shifting Letters II
#Problem You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [startᵢ, endᵢ, directionᵢ]. For every i, shift the characters in s from the index startᵢ to the index endᵢ (inclusive) forward if …
848. Shifting Letters
#Problem You are given a string s of lowercase English letters and an integer array shifts of the same length. Call the shift() of a letter, the next letter in the alphabet, (wrapping around so that 'z' becomes 'a'). For example, shift('a') …
2241. Design an ATM Machine
#Problem There is an ATM machine that stores banknotes of 5 denominations: 20, 50, 100, 200, and 500 dollars. Initially the ATM is empty. The user can use the machine to deposit or withdraw any amount of money. When withdrawing, the machine …
3398. Smallest Substring With Identical Characters I
#Problem You are given a binary string s of length n and an integer numOps. You are allowed to perform the following operation on s at most numOps times: Select any index i (where 0 <= i < n) and flip s[i]. If s[i] == '1', change s[i] to …
3399. Smallest Substring With Identical Characters II
跟 3398. Smallest Substring With Identical Characters I 一模一样,只不过 s 的长度上限从 1000 增加到 10⁵。 https://leetcode.com/problems/smallest-substring-with-identical-characters-ii/ 直接用上次的代码没问题(最大堆或二分法均可)。
1930. Unique Length-3 Palindromic Subsequences
#Problem Given a string s, return the number of unique palindromes of length three that are a subsequence of s. Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once. A palindrome is a …
3405. Count the Number of Arrays with K Matching Adjacent Elements
#Problem You are given three integers n, m, k. A good array arr of size n is defined as follows: Each element in arr is in the inclusive range [1, m]. Exactly k indices i (where 1 <= i < n) satisfy the condition arr[i - 1] == arr[i]. Return …
628. Maximum Product of Three Numbers
#Problem Given an integer array nums, find three numbers whose product is maximum and return the maximum product. https://leetcode.com/problems/maximum-product-of-three-numbers/ Example 1: Input: nums = [1,2,3] Output: 6 Example 2: Input: …
674. Longest Continuous Increasing Subsequence
#Problem Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (i.e. subarray). The subsequence must be strictly increasing. A continuous increasing subsequence is defined by two …
1128. Number of Equivalent Domino Pairs
#Problem Given a list of dominoes, dominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a == c and b == d), or (a == d and b == c) - that is, one domino can be rotated to be equal to another domino. Return the …
1260. Shift 2D Grid
#Problem Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. In one shift operation: Element at grid[i][j] moves to grid[i][j + 1]. Element at grid[i][n - 1] moves to grid[i + 1][0]. Element at grid[m - 1][n …
1374. Generate a String With Characters That Have Odd Counts
#Problem Given an integer n, return a string with n characters such that each character in such string occurs an odd number of times. The returned string must contain only lowercase English letters. If there are multiples valid strings, …
1437. Check If All 1's Are at Least Length K Places Away
#Problem Given an binary array nums and an integer k, return true if all 1’s are at least k places away from each other, otherwise return false. https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away/ Example 1: …
2270. Number of Ways to Split Array
#Problem You are given a 0-indexed integer array nums of length n. nums contains a valid split at index i if the following are true: The sum of the first i + 1 elements is greater than or equal to the sum of the last n - i - 1 elements. …
292. Nim Game
#Problem You are playing the following Nim Game with your friend: Initially, there is a heap of stones on the table. You and your friend will alternate taking turns, and you go first. On each turn, the person whose turn it is will remove 1 …
171. Excel Sheet Column Number
#Problem Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 … Z -> 26 AA -> 27 AB -> 28 … …
168. Excel Sheet Column Title
#Problem Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet. For example: A -> 1 B -> 2 C -> 3 … Z -> 26 AA -> 27 AB -> 28 … https://leetcode.com/problems/excel-sheet-column-title/ Example …
816. Ambiguous Coordinates
#Problem We had some 2-dimensional coordinates, like "(1, 3)" or "(2, 0.5)". Then, we removed all commas, decimal points, and spaces and ended up with the string s. For example, "(1, 3)" becomes s = "(13)" and "(2, 0.5)" becomes s = …
436. Find Right Interval
#Problem You are given an array of intervals, where intervals[i] = [startᵢ, endᵢ] and each startᵢ is unique. The right interval for an interval i is an interval j such that startⱼ >= endᵢ and startⱼ is minimized. Note that i may equal j. …
732. My Calendar III
#Problem A k-booking happens when k events have some non-empty intersection (i.e., there is some time that is common to all k events.) You are given some events [startTime, endTime), after each given event, return an integer k representing …