GoCalf Calf 的自留地 · 昙花一现

<Code author="Calf" />

  • 3159. Find Occurrences of an Element in an Array

    #Problem You are given an integer array nums, an integer array queries, and an integer x. For each queries[i], you need to find the index of the queries[i]ᵗʰ occurrence of x in the nums array. If there are fewer than queries[i] occurrences …

    medium
  • 494. Target Sum

    #Problem You are given an integer array nums and an integer target. You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers. For example, if nums …

    medium
  • 3083. Existence of a Substring in a String and Its Reverse

    #Problem Given a string s, find any substring of length 2 which is also present in the reverse of s. A substring is a contiguous sequence of characters within a string. Return true if such a substring exists, and false otherwise. …

    easy
  • 1847. Closest Room

    #Problem There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomIdᵢ, sizeᵢ] denotes that there is a room with room number roomIdᵢ and size equal to sizeᵢ. Each roomIdᵢ is guaranteed to be …

    hard
  • 2940. Find Building Where Alice and Bob Can Meet

    #Problem You are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the iᵗʰ building. If a person is in building i, they can move to any other building j if and only if i < j and heights[i] < …

    hard
  • 515. Find Largest Value in Each Tree Row

    #Problem Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed). https://leetcode.com/problems/find-largest-value-in-each-tree-row/ Example 1: case1Input: root = [1,3,2,5,3,null,9] Output: …

    medium
  • 3218. Minimum Cost for Cutting Cake I

    #Problem There is an m x n cake that needs to be cut into 1 x 1 pieces. You are given integers m, n, and two arrays: horizontalCut of size m - 1, where horizontalCut[i] represents the cost to cut along the horizontal line i. verticalCut of …

    medium hard
  • 3219. Minimum Cost for Cutting Cake II

    跟 3218. Minimum Cost for Cutting Cake I 一模一样,只不过 m 和 n 的量级从 20 增加到 10⁵,因此只能用 O(n log n) 贪心解法。 https://leetcode.cn/problems/minimum-cost-for-cutting-cake-ii/

    hard
  • 2360. Longest Cycle in a Graph

    #Problem You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge. The graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from …

    hard
  • 2608. Shortest Cycle in a Graph

    #Problem There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. The edges in the graph are represented by a given 2D integer array edges, where edges[i] = [uᵢ, vᵢ] denotes an edge between vertex uᵢ …

    hard
  • 2127. Maximum Employees to Be Invited to a Meeting

    #Problem A company is organizing a meeting and has a list of n employees, waiting to be invited. They have arranged for a large circular table, capable of seating any number of employees. The employees are numbered from 0 to n - 1. Each …

    hard
  • 3203. Find Minimum Diameter After Merging Two Trees

    #Problem There exist two undirected trees with n and m nodes, numbered from 0 to n - 1 and from 0 to m - 1, respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges1[i] = [aᵢ, …

    hard
  • 1705. Maximum Number of Eaten Apples

    #Problem There is a special kind of apple tree that grows apples every day for n days. On the iᵗʰ day, the tree grows apples[i] apples that will rot after days[i] days, that is on day i + days[i] the apples will be rotten and cannot be …

    medium
  • 721. Accounts Merge

    #Problem Given a list of accounts where each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account. Now, we would like to merge …

    medium
  • 685. Redundant Connection II

    #Problem In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, except for the root node which has …

    hard
  • 2471. Minimum Number of Operations to Sort a Binary Tree by Level

    #Problem You are given the root of a binary tree with unique values. In one operation, you can choose any two nodes at the same level and swap their values. Return the minimum number of operations needed to make the values at each level …

    medium
  • 855. Exam Room

    #Problem There is an exam room with n seats in a single row labeled from 0 to n - 1. When a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in …

    medium
  • 684. Redundant Connection

    #Problem In this problem, a tree is an undirected graph that is connected and has no cycles. You are given a graph that started as a tree with n nodes labeled from 1 to n, with one additional edge added. The added edge has two different …

    medium
  • 1591. Strange Printer II

    #Problem There is a strange printer with the following two special requirements: On each turn, the printer will print a solid rectangular pattern of a single color on the grid. This will cover up the existing colors in the rectangle. Once …

    hard
  • 664. Strange Printer

    #Problem There is a strange printer with the following two special properties: The printer can only print a sequence of the same character each time. At each turn, the printer can print new characters starting from and ending at any place …

    hard
  • 1387. Sort Integers by The Power Value

    #Problem The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps: if x is even then x = x / 2 if x is odd then x = 3 * x + 1 For example, the power of x = 3 is 7 because 3 needs 7 …

    medium
  • 1610. Maximum Number of Visible Points

    #Problem You are given an array points, an integer angle, and your location, where location = [pos_x, pos_y] and points[i] = [x_i, y_i] both denote integral coordinates on the X-Y plane. Initially, you are facing directly east from your …

    hard
  • 145. Binary Tree Postorder Traversal

    #Problem Given the root of a binary tree, return the postorder traversal of its nodes’ values. https://leetcode.com/problems/binary-tree-postorder-traversal/ Example 1: Input: root = [1,null,2,3] Output: [3,2,1] Explanation: case1Example 2: …

    easy
  • 2872. Maximum Number of K-Divisible Components

    #Problem There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [aᵢ, bᵢ] indicates that there is an edge between nodes aᵢ and bᵢ in the …

    hard
  • 95. Unique Binary Search Trees II

    #Problem Given an integer n, return all the structurally unique BST’s (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order. …

    medium
  • 2545. Sort the Students by Their Kth Score

    #Problem There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the iᵗʰ student got in the jᵗʰ exam. The matrix score …

    medium
  • 96. Unique Binary Search Trees

    #Problem Given an integer n, return the number of structurally unique BST’s (binary search trees) which has exactly n nodes of unique values from 1 to n. https://leetcode.com/problems/unique-binary-search-trees/ Example 1: case1Input: n = 3 …

    medium
  • 89. Gray Code

    #Problem An n-bit gray code sequence is a sequence of 2ⁿ integers where: Every integer is in the inclusive range [0, 2ⁿ - 1], The first integer is 0, An integer appears no more than once in the sequence, The binary representation of every …

    medium
  • 72. Edit Distance

    #Problem Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2. You have the following three operations permitted on a word: Insert a character Delete a character Replace a character …

    medium
  • 50. Pow(x, n)

    #Problem Implement pow(x, n), which calculates x raised to the power n (i.e., xⁿ). https://leetcode.com/problems/powx-n/ Example 1: Input: x = 2.00000, n = 10 Output: 1024.00000 Example 2: Input: x = 2.10000, n = 3 Output: 9.26100 Example …

    medium
  • 770. Basic Calculator IV

    #Problem Given an expression such as expression = "e + 8 - a + 5" and an evaluation map such as {"e": 1} (given in terms of evalvars = ["e"] and evalints = [1]), return a list of tokens representing the simplified expression, such as …

    hard
  • 227. Basic Calculator II

    #Problem Given a string s which represents an expression, evaluate this expression and return its value. The integer division should truncate toward zero. You may assume that the given expression is always valid. All intermediate results …

    medium