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/0500-0599/0559.Maximum Depth of N-ary Tree/README_EN.md
+49-14
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,11 @@ tags:
57
57
58
58
<!-- solution:start -->
59
59
60
-
### Solution 1
60
+
### Solution 1: Recursion
61
+
62
+
First, we check if $\textit{root}$ is null. If it is, we return 0. Otherwise, we initialize a variable $\textit{mx}$ to record the maximum depth of the child nodes, then traverse all the child nodes of $\textit{root}$, recursively call the $\text{maxDepth}$ function, and update the value of $\textit{mx}$. Finally, we return $\textit{mx} + 1$.
63
+
64
+
The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is the number of nodes.
Copy file name to clipboardexpand all lines: solution/0500-0599/0562.Longest Line of Consecutive One in Matrix/README_EN.md
+9-1
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,15 @@ tags:
54
54
55
55
<!-- solution:start -->
56
56
57
-
### Solution 1
57
+
### Solution 1: Dynamic Programming
58
+
59
+
We define $f[i][j][k]$ to represent the length of the longest consecutive $1$s ending at $(i, j)$ in direction $k$. The value range of $k$ is $0, 1, 2, 3$, representing horizontal, vertical, diagonal, and anti-diagonal directions, respectively.
60
+
61
+
> We can also use four 2D arrays to represent the length of the longest consecutive $1$s in the four directions.
62
+
63
+
We traverse the matrix, and when we encounter $1$, we update the value of $f[i][j][k]$. For each position $(i, j)$, we only need to update the values in its four directions. Then we update the answer.
64
+
65
+
The time complexity is $O(m \times n)$, and the space complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows and columns in the matrix, respectively.
0 commit comments