GoCalf Calf 的自留地 · 昙花一现

<Code author="Calf" />

  • 2717. Semi-Ordered Permutation

    #Problem You are given a 0-indexed permutation of n integers nums. A permutation is called semi-ordered if the first number equals 1 and the last number equals n. You can perform the below operation as many times as you want until you make …

    easy
  • 1719. Number Of Ways To Reconstruct A Tree

    #Problem You are given an array pairs, where pairs[i] = [xᵢ, yᵢ], and: There are no duplicates. xᵢ < yᵢ Let ways be the number of rooted trees that satisfy the following conditions: The tree consists of nodes whose values appeared in pairs. …

    hard difficult todo
  • 2982. Find Longest Special Substring That Occurs Thrice II

    跟 2981. Find Longest Special Substring That Occurs Thrice I 一模一样,只不过 s 的长度上限从 50 增加到 5 * 10⁵。 https://leetcode.com/problems/find-longest-special-substring-that-occurs-thrice-ii/ 直接用上次的代码没问题。

    medium
  • 2981. Find Longest Special Substring That Occurs Thrice I

    #Problem You are given a string s that consists of lowercase English letters. A string is called special if it is made up of only a single character. For example, the string "abc" is not special, whereas the strings "ddd", "zz", and "f" are …

    medium
  • 935. Knight Dialer

    #Problem The chess knight has a unique movement, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). The possible movements of chess …

    medium
  • 1982. Find Array Given Subset Sums

    #Problem You are given an integer n representing the length of an unknown array that you are trying to recover. You are also given an array sums containing the values of all 2ⁿ subset sums of the unknown array (in no particular order). …

    hard difficult
  • 954. Array of Doubled Pairs

    #Problem Given an integer array of even length arr, return true if it is possible to reorder arr such that arr[2 * i + 1] = 2 * arr[2 * i] for every 0 <= i < len(arr) / 2, or false otherwise. …

    medium
  • 2. Add Two Numbers

    #Problem You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You …

    medium
  • 3152. Special Array II

    #Problem An array is considered special if every pair of its adjacent elements contains two numbers with different parity. You are given an array of integer nums and a 2D integer matrix queries, where for queries[i] = [fromᵢ, toᵢ] your task …

    medium
  • 3151. Special Array I

    #Problem An array is considered special if every pair of its adjacent elements contains two numbers with different parity. You are given an array of integers nums. Return true if nums is a special array, otherwise, return false. …

    easy
  • 1812. Determine Color of a Chessboard Square

    #Problem You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference. problemReturn true if the square is white, and false if the square is black. The …

    easy
  • 2054. Two Best Non-Overlapping Events

    #Problem You are given a 0-indexed 2D integer array of events where events[i] = [startTimeᵢ, endTimeᵢ, valueᵢ]. The iᵗʰ event starts at startTimeᵢ and ends at endTimeᵢ, and if you attend this event, you will receive a value of valueᵢ. You …

    medium todo
  • 782. Transform to Chessboard

    #Problem You are given an n x n binary grid board. In each move, you can swap any two rows with each other, or any two columns with each other. Return the minimum number of moves to transform the board into a chessboard board. If the task …

    hard
  • 1760. Minimum Limit of Balls in a Bag

    #Problem You are given an integer array nums where the iᵗʰ bag contains nums[i] balls. You are also given an integer maxOperations. You can perform the following operation at most maxOperations times: Take any bag of balls and divide it …

    medium
  • 688. Knight Probability in Chessboard

    #Problem 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), and the bottom-right cell is (n - 1, n - 1). A chess knight …

    medium
  • 2554. Maximum Number of Integers to Choose From a Range I

    #Problem You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules: The chosen integers have to be in the range [1, n]. Each integer can be chosen at most once. …

    medium
  • 999. Available Captures for Rook

    #Problem You are given an 8 x 8 matrix representing a chessboard. There is exactly one white rook represented by 'R', some number of white bishops 'B', and some number of black pawns 'p'. Empty squares are represented by '.'. A rook can …

    easy
  • 2337. Move Pieces to Obtain a String

    #Problem You are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where: The characters 'L' and 'R' represent pieces, where a piece 'L' can move to the left only if there is …

    medium
  • 3001. Minimum Moves to Capture The Queen

    #Problem There is a 1-indexed 8 x 8 chessboard containing 3 pieces. You are given 6 integers a, b, c, d, e, and f where: (a, b) denotes the position of the white rook. (c, d) denotes the position of the white bishop. (e, f) denotes the …

    medium
  • 2056. Number of Valid Move Combinations On Chessboard

    #Problem There is an 8 x 8 chessboard containing n pieces (rooks, queens, or bishops). You are given a string array pieces of length n, where pieces[i] describes the type (rook, queen, or bishop) of the iᵗʰ piece. In addition, you are given …

    hard
  • 2825. Make String a Subsequence Using Cyclic Increments

    #Problem You are given two 0-indexed strings str1 and str2. In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', …

    medium
  • 2109. Adding Spaces to a String

    #Problem You are given a 0-indexed string s and a 0-indexed integer array spaces that describes the indices in the original string where spaces will be added. Each space should be inserted before the character at the given index. For …

    medium
  • 3274. Check if Two Chessboard Squares Have the Same Color

    #Problem You are given two strings, coordinate1 and coordinate2, representing the coordinates of a square on an 8 x 8 chessboard. Below is the chessboard for reference. problemReturn true if these two squares have the same color and false …

    easy
  • 1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence

    #Problem Given a sentence that consists of some words separated by a single space, and a searchWord, check if searchWord is a prefix of any word in sentence. Return the index of the word in sentence (1-indexed) where searchWord is a prefix …

    easy
  • 52. N-Queens II

    #Problem The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Given an integer n, return the number of distinct solutions to the n-queens puzzle. …

    hard
  • 51. N-Queens

    #Problem The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any …

    hard
  • 1531. String Compression II

    #Problem Run-length encoding is a string compression method that works by replacing consecutive identical characters (repeated 2 or more times) with the concatenation of the character and the number marking the count of the characters …

    hard difficult
  • 1346. Check If N and Its Double Exist

    #Problem Given an array arr of integers, check if there exist two indices i and j such that : i != j 0 <= i, j < arr.length arr[i] == 2 * arr[j] https://leetcode.com/problems/check-if-n-and-its-double-exist/ Example 1: Input: arr = …

    easy
  • 2097. Valid Arrangement of Pairs

    #Problem You are given a 0-indexed 2D integer array pairs where pairs[i] = [startᵢ, endᵢ]. An arrangement of pairs is valid if for every index i where 1 <= i < pairs.length, we have endᵢ₋₁ == startᵢ. Return any valid arrangement of pairs. …

    hard todo
  • 3232. Find if Digit Game Can Be Won

    #Problem You are given an array of positive integers nums. Alice and Bob are playing a game. In the game, Alice can choose either all single-digit numbers or all double-digit numbers from nums, and the rest of the numbers are given to Bob. …

    easy
  • 3250. Find the Count of Monotonic Pairs I

    #Problem You are given an array of positive integers nums of length n. We call a pair of non-negative integer arrays (arr1, arr2) monotonic if: The lengths of both arrays are n. arr1 is monotonically non-decreasing, in other words, arr1[0] …

    hard
  • 2577. Minimum Time to Visit a Cell In a Grid

    #Problem You are given a m x n matrix grid consisting of non-negative integers where grid[row][col] represents the minimum time required to be able to visit the cell (row, col), which means you can visit the cell (row, col) only when the …

    hard