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/1600-1699/1614.Maximum Nesting Depth of the Parentheses/README_EN.md
+9-1
Original file line number
Diff line number
Diff line change
@@ -69,7 +69,15 @@ tags:
69
69
70
70
<!-- solution:start -->
71
71
72
-
### Solution 1
72
+
### Solution 1: Traversal
73
+
74
+
We use a variable $d$ to record the current depth, initially $d = 0$.
75
+
76
+
Traverse the string $s$. When encountering a left parenthesis, increment the depth $d$ by one and update the answer to be the maximum of the current depth $d$ and the answer. When encountering a right parenthesis, decrement the depth $d$ by one.
77
+
78
+
Finally, return the answer.
79
+
80
+
The time complexity is $O(n)$, where $n$ is the length of the string $s$. The space complexity is $O(1)$.
Copy file name to clipboardexpand all lines: solution/1600-1699/1615.Maximal Network Rank/README_EN.md
+15-36
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,13 @@ tags:
73
73
74
74
<!-- solution:start -->
75
75
76
-
### Solution 1
76
+
### Solution 1: Counting
77
+
78
+
We can use a one-dimensional array $\textit{cnt}$ to record the degree of each city and a two-dimensional array $\textit{g}$ to record whether there is a road between each pair of cities. If there is a road between city $a$ and city $b$, then $\textit{g}[a][b] = \textit{g}[b][a] = 1$; otherwise, $\textit{g}[a][b] = \textit{g}[b][a] = 0$.
79
+
80
+
Next, we enumerate each pair of cities $(a, b)$, where $a \lt b$, and calculate their network rank, which is $\textit{cnt}[a] + \textit{cnt}[b] - \textit{g}[a][b]$. The maximum value among these is the answer.
81
+
82
+
The time complexity is $O(n^2)$, and the space complexity is $O(n^2)$. Here, $n$ is the number of cities.
0 commit comments