|
6 | 6 |
|
7 | 7 | <!-- 这里写题目描述 -->
|
8 | 8 |
|
9 |
| -<p>给你一个大小为 <code>rows x cols</code> 的矩阵 <code>grid</code> 。最初,你位于左上角 <code>(0, 0)</code> ,每一步,你可以在矩阵中 <strong>向右</strong> 或 <strong>向下</strong> 移动。</p> |
| 9 | +<p>给你一个大小为 <code>m x n</code> 的矩阵 <code>grid</code> 。最初,你位于左上角 <code>(0, 0)</code> ,每一步,你可以在矩阵中 <strong>向右</strong> 或 <strong>向下</strong> 移动。</p> |
10 | 10 |
|
11 |
| -<p>在从左上角 <code>(0, 0)</code> 开始到右下角 <code>(rows - 1, cols - 1)</code> 结束的所有路径中,找出具有 <strong>最大非负积</strong> 的路径。路径的积是沿路径访问的单元格中所有整数的乘积。</p> |
| 11 | +<p>在从左上角 <code>(0, 0)</code> 开始到右下角 <code>(m - 1, n - 1)</code> 结束的所有路径中,找出具有 <strong>最大非负积</strong> 的路径。路径的积是沿路径访问的单元格中所有整数的乘积。</p> |
12 | 12 |
|
13 |
| -<p>返回 <strong>最大非负积 </strong>对<strong><em> </em><code>10<sup>9</sup> + 7</code></strong> <strong>取余</strong> 的结果。如果最大积为负数,则返回<em> </em><code>-1</code> 。</p> |
| 13 | +<p>返回 <strong>最大非负积 </strong>对<strong><em> </em><code>10<sup>9</sup> + 7</code></strong> <strong>取余</strong> 的结果。如果最大积为 <strong>负数</strong> ,则返回<em> </em><code>-1</code> 。</p> |
14 | 14 |
|
15 | 15 | <p><strong>注意,</strong>取余是在得到最大积之后执行的。</p>
|
16 | 16 |
|
17 | 17 | <p> </p>
|
18 | 18 |
|
19 | 19 | <p><strong>示例 1:</strong></p>
|
20 |
| - |
21 |
| -<pre><strong>输入:</strong>grid = [[-1,-2,-3], |
22 |
| - [-2,-3,-3], |
23 |
| - [-3,-3,-2]] |
| 20 | +<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1500-1599/1594.Maximum%20Non%20Negative%20Product%20in%20a%20Matrix/images/product1.jpg" style="width: 244px; height: 245px;" /> |
| 21 | +<pre> |
| 22 | +<strong>输入:</strong>grid = [[-1,-2,-3],[-2,-3,-3],[-3,-3,-2]] |
24 | 23 | <strong>输出:</strong>-1
|
25 |
| -<strong>解释:</strong>从 (0, 0) 到 (2, 2) 的路径中无法得到非负积,所以返回 -1 |
26 |
| -</pre> |
| 24 | +<strong>解释:</strong>从 (0, 0) 到 (2, 2) 的路径中无法得到非负积,所以返回 -1 。</pre> |
27 | 25 |
|
28 | 26 | <p><strong>示例 2:</strong></p>
|
29 |
| - |
30 |
| -<pre><strong>输入:</strong>grid = [[<strong>1</strong>,-2,1], |
31 |
| - [<strong>1</strong>,<strong>-2</strong>,1], |
32 |
| - [3,<strong>-4</strong>,<strong>1</strong>]] |
| 27 | +<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1500-1599/1594.Maximum%20Non%20Negative%20Product%20in%20a%20Matrix/images/product2.jpg" style="width: 244px; height: 245px;" /> |
| 28 | +<pre> |
| 29 | +<strong>输入:</strong>grid = [[1,-2,1],[1,-2,1],[3,-4,1]] |
33 | 30 | <strong>输出:</strong>8
|
34 |
| -<strong>解释:</strong>最大非负积对应的路径已经用粗体标出 (1 * 1 * -2 * -4 * 1 = 8) |
| 31 | +<strong>解释:</strong>最大非负积对应的路径如图所示 (1 * 1 * -2 * -4 * 1 = 8) |
35 | 32 | </pre>
|
36 | 33 |
|
37 | 34 | <p><strong>示例 3:</strong></p>
|
38 |
| - |
39 |
| -<pre><strong>输入:</strong>grid = [[<strong>1</strong>, 3], |
40 |
| - [<strong>0</strong>,<strong>-4</strong>]] |
| 35 | +<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1500-1599/1594.Maximum%20Non%20Negative%20Product%20in%20a%20Matrix/images/product3.jpg" style="width: 164px; height: 165px;" /> |
| 36 | +<pre> |
| 37 | +<strong>输入:</strong>grid = [[1,3],[0,-4]] |
41 | 38 | <strong>输出:</strong>0
|
42 |
| -<strong>解释:</strong>最大非负积对应的路径已经用粗体标出 (1 * 0 * -4 = 0) |
43 |
| -</pre> |
44 |
| - |
45 |
| -<p><strong>示例 4:</strong></p> |
46 |
| - |
47 |
| -<pre><strong>输入:</strong>grid = [[ <strong>1</strong>, 4,4,0], |
48 |
| - [<strong>-2</strong>, 0,0,1], |
49 |
| - [ <strong>1</strong>,<strong>-1</strong>,<strong>1</strong>,<strong>1</strong>]] |
50 |
| -<strong>输出:</strong>2 |
51 |
| -<strong>解释:</strong>最大非负积对应的路径已经用粗体标出 (1 * -2 * 1 * -1 * 1 * 1 = 2) |
| 39 | +<strong>解释:</strong>最大非负积对应的路径如图所示 (1 * 0 * -4 = 0) |
52 | 40 | </pre>
|
53 | 41 |
|
54 | 42 | <p> </p>
|
55 | 43 |
|
56 | 44 | <p><strong>提示:</strong></p>
|
57 | 45 |
|
58 | 46 | <ul>
|
59 |
| - <li><code>1 <= rows, cols <= 15</code></li> |
| 47 | + <li><code>m == grid.length</code></li> |
| 48 | + <li><code>n == grid[i].length</code></li> |
| 49 | + <li><code>1 <= m, n <= 15</code></li> |
60 | 50 | <li><code>-4 <= grid[i][j] <= 4</code></li>
|
61 | 51 | </ul>
|
62 | 52 |
|
|
0 commit comments