<Code author="Calf" />
3251. Find the Count of Monotonic Pairs II
跟 3250. Find the Count of Monotonic Pairs I 一模一样,只不过 nums[i] 的上限从 50 增加到 1000。 https://leetcode.cn/problems/find-the-count-of-monotonic-pairs-ii/ 直接用上次的代码似乎问题不大。
743. Network Delay Time
#Problem You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (uᵢ, vᵢ, wᵢ), where uᵢ is the source node, vᵢ is the target node, and wᵢ is the time it takes …
2290. Minimum Obstacle Removal to Reach Corner
#Problem You are given a 0-indexed 2D integer array grid of size m x n. Each cell has one of two values: 0 represents an empty cell, 1 represents an obstacle that may be removed. You can move up, down, left, or right from and to an empty …
443. String Compression
#Problem Given an array of characters chars, compress it using the following algorithm: Begin with an empty string s. For each group of consecutive repeating characters in chars: If the group’s length is 1, append the character to s. …
796. Rotate String
#Problem Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s. A shift on s consists of moving the leftmost character of s to the rightmost position. For example, if s = "abcde", then …
2490. Circular Sentence
#Problem A sentence is a list of words that are separated by a single space with no leading or trailing spaces. For example, "Hello World", "HELLO", "hello world hello world" are all sentences. Words consist of only uppercase and lowercase …
1957. Delete Characters to Make Fancy String
#Problem A fancy string is a string where no three consecutive characters are equal. Given a string s, delete the minimum possible number of characters from s to make it fancy. Return the final string after the deletion. It can be shown …
3254. Find the Power of K-Size Subarrays I
#Problem You are given an array of integers nums of length n and a positive integer k. The power of an array is defined as: Its maximum element if all of its elements are consecutive and sorted in ascending order. -1 otherwise. You need to …
3255. Find the Power of K-Size Subarrays II
跟 3254. Find the Power of K-Size Subarrays I 一模一样,只不过 n 的上限从 500 增加到 10⁵。 https://leetcode.cn/problems/find-the-power-of-k-size-subarrays-ii/
3222. Find the Winning Player in Coin Game
#Problem You are given two positive integers x and y, denoting the number of coins with values 75 and 10 respectively. Alice and Bob are playing a game. Each turn, starting with Alice, the player must pick up coins with a total value 115. …
633. Sum of Square Numbers
#Problem Given a non-negative integer c, decide whether there’re two integers a and b such that a² + b² = c. https://leetcode.cn/problems/sum-of-square-numbers/ Example 1: Input: c = 5 Output: true Explanation: 1 * 1 + 2 * 2 = 5 Example 2: …
3208. Alternating Groups II
#Problem There is a circle of red and blue tiles. You are given an array of integers colors and an integer k. The color of tile i is represented by colors[i]: colors[i] == 0 means that tile i is red. colors[i] == 1 means that tile i is …
638. Shopping Offers
#Problem In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price. You are given an integer array …
3226. Number of Bit Changes to Make Two Integers Equal
#Problem You are given two positive integers n and k. You can choose any bit in the binary representation of n that is equal to 1 and change it to 0. Return the number of changes needed to make n equal to k. If it is impossible, return -1. …
3259. Maximum Energy Boost From Two Drinks
#Problem You are given two integer arrays energyDrinkA and energyDrinkB of the same length n by a futuristic sports scientist. These arrays represent the energy boosts per hour provided by two different energy drinks, A and B, respectively. …
2924. Find Champion II
#Problem There are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG. You are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG, where edges[i] = [uᵢ, vᵢ] indicates …
2923. Find Champion I
#Problem There are n teams numbered from 0 to n - 1 in a tournament. Given a 0-indexed 2D boolean matrix grid of size n * n. For all i, j that 0 <= i, j <= n - 1 and i != j team i is stronger than team j if grid[i][j] == 1, otherwise, team …
125. Valid Palindrome
#Problem A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers. …
3206. Alternating Groups I
#Problem There is a circle of red and blue tiles. You are given an array of integers colors. The color of tile i is represented by colors[i]: colors[i] == 0 means that tile i is red. colors[i] == 1 means that tile i is blue. Every 3 …
124. Binary Tree Maximum Path Sum
#Problem A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the …
121. Best Time to Buy and Sell Stock
#Problem You are given an array prices where prices[i] is the price of a given stock on the iᵗʰ day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. …
371. Sum of Two Integers
#Problem Given two integers a and b, return the sum of the two integers without using the operators + and -. https://leetcode.com/problems/sum-of-two-integers/ Example 1: Input: a = 1, b = 2 Output: 3 Example 2: Input: a = 2, b = 3 Output: …
242. Valid Anagram
#Problem Given two strings s and t, return true if t is an anagram of s, and false otherwise. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, using all the original letters exactly once. …
238. Product of Array Except Self
#Problem Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. You …
235. Lowest Common Ancestor of a Binary Search Tree
#Problem Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the …
377. Combination Sum IV
#Problem Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target. The test cases are generated so that the answer can fit in a 32-bit integer. …
105. Construct Binary Tree from Preorder and Inorder Traversal
#Problem Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree. …
632. Smallest Range Covering Elements from K Lists
#Problem You have k lists of sorted integers in non-decreasing order. Find the smallest range that includes at least one number from each of the k lists. We define the range [a, b] is smaller than range [c, d] if b - a < d - c or a < c if b …
104. Maximum Depth of Binary Tree
#Problem Given the root of a binary tree, return its maximum depth. A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. …
230. Kth Smallest Element in a BST
#Problem Given the root of a binary search tree, and an integer k, return the kᵗʰ smallest value (1-indexed) of all the values of the nodes in the tree. https://leetcode.com/problems/kth-smallest-element-in-a-bst/ Example 1: case1Input: …
102. Binary Tree Level Order Traversal
#Problem Given the root of a binary tree, return the level order traversal of its nodes’ values. (i.e., from left to right, level by level). https://leetcode.com/problems/binary-tree-level-order-traversal/ Example 1: case1Input: root = …
1143. Longest Common Subsequence
#Problem Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with some …