<Code author="Calf" />
1728. Cat and Mouse II
#Problem A game is played by a cat and a mouse named Cat and Mouse. The environment is represented by a grid of size rows x cols, where each element is a wall, floor, player (Cat, Mouse), or food. Players are represented by the characters …
1910. Remove All Occurrences of a Substring
#Problem Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed: Find the leftmost occurrence of the substring part and remove it from s. Return s after removing all …
3174. Clear Digits
#Problem You are given a string s. Your task is to remove all digits by doing this operation repeatedly: Delete the first digit and the closest non-digit character to its left. Return the resulting string after removing all digits. …
2364. Count Number of Bad Pairs
#Problem You are given a 0-indexed integer array nums. A pair of indices (i, j) is a bad pair if i < j and j - i != nums[j] - nums[i]. Return the total number of bad pairs in nums. https://leetcode.com/problems/count-number-of-bad-pairs/ …
80. Remove Duplicates from Sorted Array II
#Problem Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice. The relative order of the elements should be kept the same. Since it is impossible to …
26. Remove Duplicates from Sorted Array
#Problem Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of …
2349. Design a Number Container System
#Problem Design a number container system that can do the following: Insert or Replace a number at the given index in the system. Return the smallest index for the given number in the system. Implement the NumberContainers class: …
63. Unique Paths II
#Problem You are given an m x n integer array grid. There is a robot initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either …
3160. Find the Number of Distinct Colors Among the Balls
#Problem You are given an integer limit and a 2D array queries of size n x 2. There are limit + 1 balls with distinct labels in the range [0, limit]. Initially, all balls are uncolored. For every query in queries that is of the form [x, y], …
59. Spiral Matrix II
#Problem Given a positive integer n, generate an n x n matrix filled with elements from 1 to n² in spiral order. https://leetcode.cn/problems/spiral-matrix-ii/ Example 1: case1Input: n = 3 Output: [[1,2,3],[8,9,4],[7,6,5]] Example 2: Input: …
47. Permutations II
#Problem Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order. https://leetcode.cn/problems/permutations-ii/ Example 1: Input: nums = [1,1,2] Output: json 复制 [[1,1,2], …
1726. Tuple with Same Product
#Problem Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d. …
46. Permutations
#Problem Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. A permutation is a rearrangement of all the elements of an array. https://leetcode.cn/problems/permutations/ …
1790. Check if One String Swap Can Make Strings Equal
#Problem You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices. Return true if it is possible to make …
90. Subsets II
#Problem Given an integer array nums that may contain duplicates, return all possible subsets (the power set). A subset of an array is a selection of elements (possibly none) of the array. The solution set must not contain duplicate …
78. Subsets
#Problem Given an integer array nums of unique elements, return all possible subsets (the power set). A subset of an array is a selection of elements (possibly none) of the array. The solution set must not contain duplicate subsets. Return …
1800. Maximum Ascending Subarray Sum
#Problem Given an array of positive integers nums, return the maximum possible sum of an ascending subarray in nums. A subarray is defined as a contiguous sequence of numbers in an array. A subarray [numsl, numsl+1, ..., numsr-1, numsr] is …
922. Sort Array By Parity II
#Problem Given an array of integers nums, half of the integers in nums are odd, and the other half are even. Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even. Return any answer array that …
905. Sort Array By Parity
#Problem Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers. Return any array that satisfies this condition. https://leetcode.cn/problems/sort-array-by-parity/ Example 1: …
3105. Longest Strictly Increasing or Strictly Decreasing Subarray
#Problem You are given an array of integers nums. Return the length of the longest subarray of nums which is either strictly increasing or strictly decreasing. A subarray is a contiguous non-empty sequence of elements within an array. An …
680. Valid Palindrome II
#Problem Given a string s, return true if the s can be palindrome after deleting at most one character from it. https://leetcode.cn/problems/valid-palindrome-ii/ Example 1: Input: s = "aba" Output: true Example 2: Input: s = "abca" Output: …
1752. Check if Array Is Sorted and Rotated
#Problem Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false. There may be duplicates in the original array. Note: An …
598. Range Addition II
#Problem You are given an m x n matrix M initialized with all 0’s and an array of operations ops, where ops[i] = [aᵢ, bᵢ] means M[x][y] should be incremented by one for all 0 <= x < aᵢ and 0 <= y < bᵢ. Count and return the number of maximum …
81. Search in Rotated Sorted Array II
#Problem There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values). Before being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resulting …
827. Making A Large Island
#Problem You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applying this operation. An island is a 4-directionally connected group of 1s. …
541. Reverse String II
#Problem Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string. If there are fewer than k characters left, reverse all of them. If there are less than 2k but greater …
344. Reverse String
#Problem Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place with O(1) extra memory. https://leetcode.cn/problems/reverse-string/ Example 1: …
350. Intersection of Two Arrays II
#Problem Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order. …
349. Intersection of Two Arrays
#Problem Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order. https://leetcode.cn/problems/intersection-of-two-arrays/ Example …
219. Contains Duplicate II
#Problem Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k. https://leetcode.cn/problems/contains-duplicate-ii/ Example 1: …
118. Pascal’s Triangle
#Problem Given an integer numRows, return the first numRows of Pascal’s triangle. In Pascal’s triangle, each number is the sum of the two numbers directly above it as shown: https://leetcode.cn/problems/pascals-triangle/ pascalExample 1: …
2658. Maximum Number of Fish in a Grid
#Problem You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents: A land cell if grid[r][c] = 0, or A water cell containing grid[r][c] fish, if grid[r][c] > 0. A fisher can start at any water cell (r, c) and can do …