Skip to content

Commit ad6ddee

Browse files
committed
deploy: 355400e
1 parent 10958ff commit ad6ddee

File tree

9 files changed

+377
-169
lines changed

9 files changed

+377
-169
lines changed

en/lc/559/index.html

Lines changed: 75 additions & 19 deletions
Large diffs are not rendered by default.

en/lc/562/index.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19170,9 +19170,9 @@
1917019170
<ul class="md-nav__list">
1917119171

1917219172
<li class="md-nav__item">
19173-
<a href="#solution-1" class="md-nav__link">
19173+
<a href="#solution-1-dynamic-programming" class="md-nav__link">
1917419174
<span class="md-ellipsis">
19175-
Solution 1
19175+
Solution 1: Dynamic Programming
1917619176
</span>
1917719177
</a>
1917819178

@@ -81910,7 +81910,13 @@ <h2 id="description">Description</h2>
8191081910
<h2 id="solutions">Solutions</h2>
8191181911
<!-- solution:start -->
8191281912

81913-
<h3 id="solution-1">Solution 1</h3>
81913+
<h3 id="solution-1-dynamic-programming">Solution 1: Dynamic Programming</h3>
81914+
<p>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.</p>
81915+
<blockquote>
81916+
<p>We can also use four 2D arrays to represent the length of the longest consecutive $1$s in the four directions.</p>
81917+
</blockquote>
81918+
<p>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.</p>
81919+
<p>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.</p>
8191481920
<div class="tabbed-set tabbed-alternate" data-tabs="1:4"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Python3</label><label for="__tabbed_1_2">Java</label><label for="__tabbed_1_3">C++</label><label for="__tabbed_1_4">Go</label></div>
8191581921
<div class="tabbed-content">
8191681922
<div class="tabbed-block">

en/lc/563/index.html

Lines changed: 106 additions & 63 deletions
Large diffs are not rendered by default.

en/lc/566/index.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19254,9 +19254,9 @@
1925419254
<ul class="md-nav__list">
1925519255

1925619256
<li class="md-nav__item">
19257-
<a href="#solution-1" class="md-nav__link">
19257+
<a href="#solution-1-simulation" class="md-nav__link">
1925819258
<span class="md-ellipsis">
19259-
Solution 1
19259+
Solution 1: Simulation
1926019260
</span>
1926119261
</a>
1926219262

@@ -81923,7 +81923,11 @@ <h2 id="description">Description</h2>
8192381923
<h2 id="solutions">Solutions</h2>
8192481924
<!-- solution:start -->
8192581925

81926-
<h3 id="solution-1">Solution 1</h3>
81926+
<h3 id="solution-1-simulation">Solution 1: Simulation</h3>
81927+
<p>First, we get the number of rows and columns of the original matrix, denoted as $m$ and $n$ respectively. If $m \times n \neq r \times c$, then the matrix cannot be reshaped, and we return the original matrix directly.</p>
81928+
<p>Otherwise, we create a new matrix with $r$ rows and $c$ columns. Starting from the first element of the original matrix, we traverse all elements in row-major order and place the traversed elements into the new matrix in order.</p>
81929+
<p>After traversing all elements of the original matrix, we get the answer.</p>
81930+
<p>The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows and columns of the original matrix, respectively. Ignoring the space consumption of the answer, the space complexity is $O(1)$.</p>
8192781931
<div class="tabbed-set tabbed-alternate" data-tabs="1:7"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><input id="__tabbed_1_7" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Python3</label><label for="__tabbed_1_2">Java</label><label for="__tabbed_1_3">C++</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">TypeScript</label><label for="__tabbed_1_6">Rust</label><label for="__tabbed_1_7">C</label></div>
8192881932
<div class="tabbed-content">
8192981933
<div class="tabbed-block">

en/search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lc/559/index.html

Lines changed: 74 additions & 18 deletions
Large diffs are not rendered by default.

lc/562/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86522,7 +86522,7 @@ <h3 id="_3">方法一:动态规划</h3>
8652286522
<p>我们也可以用四个二维数组分别表示四个方向的最长连续 $1$ 的长度。</p>
8652386523
</blockquote>
8652486524
<p>遍历矩阵,当遇到 $1$ 时,更新 $f[i][j][k]$ 的值。对于每个位置 $(i, j)$,我们只需要更新其四个方向的值即可。然后更新答案。</p>
86525-
<p>时间复杂度 $O(m\times n)$,空间复杂度 $O(m\times n)$。其中 $m$ 和 $n$ 分别为矩阵的行数和列数。</p>
86525+
<p>时间复杂度 $O(m \times n)$,空间复杂度 $O(m \times n)$。其中 $m$ 和 $n$ 分别为矩阵的行数和列数。</p>
8652686526
<div class="tabbed-set tabbed-alternate" data-tabs="1:4"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Python3</label><label for="__tabbed_1_2">Java</label><label for="__tabbed_1_3">C++</label><label for="__tabbed_1_4">Go</label></div>
8652786527
<div class="tabbed-content">
8652886528
<div class="tabbed-block">

0 commit comments

Comments
 (0)