[LeetCode] 2468. Split Message Based on Limit

2468. Split Message Based on Limit Hardness: \(\color{red}\textsf{Hard}\) Ralated Topics: String、Binary Search \(\color{blue}\textsf{Biweekly Contest 91}\) 一、題目 You are given a string, message, and a positive integer, limit. You must split message into one or more parts based on limit. Each resulting part should have the suffix "<a/b>", where "b" is to be replaced with the total number of parts and "a" is to be replaced with the index of the part, starting from 1 and going up to b. Additionally, the length of each resulting part (including its suffix) should be equal to limit, except for the last part whose length can be at most limit. ...

<span title='2022-11-24 01:09:57 +0800 +0800'>November 24, 2022</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 2467. Most Profitable Path in a Tree

2467. Most Profitable Path in a Tree Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Array、Tree、Depth-First Search、Breadth-First Search、Graph \(\color{blue}\textsf{Biweekly Contest 91}\) 一、題目 There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. At every node i, there is a gate. You are also given an array of even integers amount, where amount[i] represents: ...

<span title='2022-11-24 01:09:51 +0800 +0800'>November 24, 2022</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 1926. Nearest Exit from Entrance in Maze

1926. Nearest Exit from Entrance in Maze Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Array、Breadth-First Search、Matrix 一、題目 You are given an m x n matrix maze (0-indexed) with empty cells (represented as '.') and walls (represented as '+'). You are also given the entrance of the maze, where entrance = [entrancerow, entrancecol] denotes the row and column of the cell you are initially standing at. In one step, you can move one cell up, down, left, or right. You cannot step into a cell with a wall, and you cannot step outside the maze. Your goal is to find the nearest exit from the entrance. An exit is defined as an empty cell that is at the border of the maze. The entrance does not count as an exit. ...

<span title='2022-11-22 23:41:58 +0800 +0800'>November 22, 2022</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 279. Perfect Squares

279. Perfect Squares Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Math、Dynamic Programming、Breadth-First Search 一、題目 Given an integer n, return the least number of perfect square numbers that sum to n. A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not. Example 1: ...

<span title='2022-11-22 19:40:18 +0800 +0800'>November 22, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 337. House Robber III

337. House Robber III Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Dynamic Programming、Tree、Depth-First Search、Binary Tree 一、題目 The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root. Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that all houses in this place form a binary tree. It will automatically contact the police if two directly-linked houses were broken into on the same night. Given the root of the binary tree, return the maximum amount of money the thief can rob without alerting the police. ...

<span title='2022-11-19 21:43:08 +0800 +0800'>November 19, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 587. Erect the Fence

587. Erect the Rence Hardness: \(\color{red}\textsf{Hard}\) Ralated Topics: Array、Math、Geometry 一、題目 You are given an array trees where trees[i] = [xi, yi] represents the location of a tree in the garden. You are asked to fence the entire garden using the minimum length of rope as it is expensive. The garden is well fenced only if all the trees are enclosed. Return the coordinates of trees that are exactly located on the fence perimeter. ...

<span title='2022-11-19 16:56:09 +0800 +0800'>November 19, 2022</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 322. Coin Change

322. Coin Change Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Array、Dynamic Programming、Breadth-First Search 一、題目 You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1. You may assume that you have an infinite number of each kind of coin. ...

<span title='2022-11-17 21:31:45 +0800 +0800'>November 17, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 2466. Count Ways To Build Good Strings

2466. Count Ways To Build Good Strings Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Dynamic Programming \(\color{blue}\textsf{Biweekly Contest 91}\) 一、題目 Given the integers zero, one, low, and high, we can construct a string by starting with an empty string, and then at each step perform either of the following: Append the character '0' zero times. Append the character '1' one times. This can be performed any number of times. A good string is a string constructed by the above process having a length between low and high (inclusive). Return the number of different good strings that can be constructed satisfying these properties. Since the answer can be large, return it modulo 10^9 + 7. Example 1: ...

<span title='2022-11-17 21:23:24 +0800 +0800'>November 17, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 2465. Number of Distinct Averages

2465. Number of Distinct Averages Hardness: \(\color{green}\textsf{Easy}\) Ralated Topics: Array、Hash Table、Two Pointers、Sorting \(\color{blue}\textsf{Biweekly Contest 91}\) 一、題目 You are given a 0-indexed integer array nums of even length. As long as nums is not empty, you must repetitively: Find the minimum number in nums and remove it. Find the maximum number in nums and remove it. Calculate the average of the two removed numbers. The average of two numbers a and b is (a + b) / 2. For example, the average of 2 and 3 is (2 + 3) / 2 = 2.5. Return the number of distinct averages calculated using the above process. Note that when there is a tie for a minimum or maximum number, any can be removed. Example 1: ...

<span title='2022-11-17 21:00:05 +0800 +0800'>November 17, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 223. Rectangle Area

223. Rectangle Area Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Math、Geometry 一、題目 Given the coordinates of two rectilinear rectangles in a 2D plane, return the total area covered by the two rectangles. The first rectangle is defined by its bottom-left corner (ax1, ay1) and its top-right corner (ax2, ay2). The second rectangle is defined by its bottom-left corner (bx1, by1) and tis top-right corner (bx2, by2). Example 1: Input: ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2 Output: 45 Example 2: ...

<span title='2022-11-17 20:39:17 +0800 +0800'>November 17, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu