[LeetCode] 1834. Single-Threaded CPU

1834. Single-Threaded CPU Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Array、Sorting、Heap (Priority Queue> 一、題目 You are given n​​​​ tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTimei, processingTimei] means that the i​​​​​​th​​​​ task will be available to process at enqueueTimei and will take processingTimei to finish processing. You have a single-threaded CPU that can process at most one task at a time and will act in the following way: ...

<span title='2022-12-29 22:49:27 +0800 +0800'>December 29, 2022</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 1962. Remove Stones to Minimize the Total

1962. Remove Stones to Minimize the Total Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Array、Heap (Priority Queue) 一、題目 You are given a 0-indexed integer array piles, where piles[i] represents the number of stones in the ith pile, and an integer k. You should apply the following operation exactly k times: Choose any piles[i] and remove floor(piles[i] / 2) stones from it. Notice that you can apply the operation on the same pile more than once. Return the minimum possible total number of stones remaining after applying the k operations. floor(x) is the greatest integer that is smaller than or equal to x (i.e., rounds x down). ...

<span title='2022-12-29 00:03:22 +0800 +0800'>December 29, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 2279. Maximum Bags With Full Capacity of Rocks

2279. Maximum Bags With Full Capacity of Rocks Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Array、Greedy、Sorting 一、題目 You have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The ith bag can hold a maximum of capacity[i] rocks and currently contains rocks[i] rocks. You are also given an integer additionalRocks, the number of additional rocks you can place in any of the bags. Return the maximum number of bags that could have full capacity after placing the additional rocks in some bags. ...

<span title='2022-12-27 20:48:32 +0800 +0800'>December 27, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 2389. Longest Subsequence With Limited Sum

2389. Longest Subsequence With Limited Sum Hardness: \(\color{green}\textsf{Easy}\) Ralated Topics: Array、Binary Search、Greedy、Sorting、Prefix Sum 一、題目 You are given an integer array nums of length n, and an integer array queries of length m. Return an array answer of length m where answer[i] is the maximum size of a subsequence that you can take from nums such that the sum of its elements is less than or equal to queries[i]. A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements. ...

<span title='2022-12-25 20:07:51 +0800 +0800'>December 25, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 790. Domino and Tromino Tiling

790. Domino and Tromino Tiling Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Dynamic Programming 一、題目 You have two types of tiles: a 2 x 1 domino shape and a tromino shape. You may rotate these shapes. Given an integer n, return the number of ways to tile an 2 x n board. Since the answer may be very large, return it modulo 10^9 + 7. In a tiling, every square must be covered by a tile. Two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile. ...

<span title='2022-12-24 23:53:10 +0800 +0800'>December 24, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 841. Keys and Rooms

841. Keys and Rooms Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Depth-First Search、Breadth-First Search、Graph 一、題目 There are n rooms labeled from 0 to n - 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key. When you visit a room, you may find a set of distinct keys in it. Each key has a number on it, denoting which room it unlocks, and you can take all of them with you to unlock the other rooms. Given an array rooms where rooms[i] is the set of keys that you can obtain if you visited room i, return true if you can visit all the rooms, or false otherwise. ...

<span title='2022-12-20 23:00:22 +0800 +0800'>December 20, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 25. Reverse Nodes in k-Group

25. Reverse Nodes in k-Group Hardness: \(\color{red}\textsf{Hard}\) Ralated Topics: Linked List、Recursion 一、題目 Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list. k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is. You may not alter the values in the list’s nodes, only nodes themselves may be changed. ...

<span title='2022-12-16 23:32:48 +0800 +0800'>December 16, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 24. Swap Nodes in Pairs

24. Swap Nodes in Pairs Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Linked List、Recursion 一、題目 Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list’s nodes (i.e., only nodes themselves may be changed.) Example 1: Input: head = [1,2,3,4] Output: [2,1,4,3] Example 2: Input: head = [] Output: [] Example 3: Input: head = [1] Output: [1] Constraints: ...

<span title='2022-12-14 23:35:28 +0800 +0800'>December 14, 2022</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 931. Minimum Falling Path Sum

931. Minimum Falling Path Sum Hardness: \(\color{orange}\textsf{Medium}\) Ralated Topics: Array、Dynamic Programming、Matrix 一、題目 Given an n x n array of integers matrix, return the minimum sum of any falling path through matrix. A falling path starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position (row, col) will be (row + 1, col - 1), (row + 1, col), or (row + 1, col + 1). ...

<span title='2022-12-13 21:53:27 +0800 +0800'>December 13, 2022</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Rain Hu

[LeetCode] 70. Climbing Stairs

70. Climbing Stairs Hardness: \(\color{green}\textsf{Easy}\) Ralated Topics: Math、Dynamic Programming、Memoization 一、題目 You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example 1: Input: n = 2 Output: 2 Explanation: There are two ways to climb to the top. 1 step + 1 step 2 steps Example 2: ...

<span title='2022-12-12 22:43:20 +0800 +0800'>December 12, 2022</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;Rain Hu