You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/2300-2399/2397.Maximum Rows Covered by Columns/README_EN.md
+41
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,14 @@ Therefore, we return 2.
55
55
56
56
## Solutions
57
57
58
+
**Solution 1: Binary Enumeration**
59
+
60
+
First, we convert each row of the matrix into a binary number and record it in the array $rows$. Here, $rows[i]$ represents the binary number corresponding to the $i$-th row, and the $j$-th bit of this binary number $rows[i]$ represents the value of the $i$-th row and $j$-th column.
61
+
62
+
Next, we enumerate all $2^n$ column selection schemes, where $n$ is the number of columns in the matrix. For each column selection scheme, we check whether `numSelect` columns have been selected. If not, we skip it. Otherwise, we count how many rows in the matrix are covered by the selected columns, i.e., how many binary numbers $rows[i]$ are equal to the bitwise AND of $rows[i]$ and the column selection scheme $mask$. We then update the maximum number of rows.
63
+
64
+
The time complexity is $O(2^n \times m)$, and the space complexity is $O(m)$. Where $m$ and $n$ are the number of rows and columns in the matrix, respectively.
Copy file name to clipboardexpand all lines: solution/2400-2499/2487.Remove Nodes From Linked List/README_EN.md
+49-4
Original file line number
Diff line number
Diff line change
@@ -40,6 +40,14 @@
40
40
41
41
## Solutions
42
42
43
+
**Solution 1: Monotonic Stack Simulation**
44
+
45
+
We can first store the node values of the linked list into an array $nums$. Then, we traverse the array $nums$, maintaining a stack $stk$ that is monotonically decreasing from the bottom to the top. If the current element is larger than the top element of the stack, we pop the top element of the stack until the current element is less than or equal to the top element, and then we push the current element into the stack.
46
+
47
+
Finally, we construct the resulting linked list from the bottom to the top of the stack, which is the answer.
48
+
49
+
The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is the length of the linked list.
0 commit comments