|
1 |
| -# [2510. Check if There is a Path With Equal Number of 0's And 1's](https://leetcode.cn/problems/check-if-there-is-a-path-with-equal-number-of-0s-and-1s) |
| 1 | +# [2510. 检查是否有路径经过相同数量的 0 和 1](https://leetcode.cn/problems/check-if-there-is-a-path-with-equal-number-of-0s-and-1s) |
2 | 2 |
|
3 | 3 | [English Version](/solution/2500-2599/2510.Check%20if%20There%20is%20a%20Path%20With%20Equal%20Number%20of%200%27s%20And%201%27s/README_EN.md)
|
4 | 4 |
|
5 | 5 | ## 题目描述
|
6 | 6 |
|
7 | 7 | <!-- 这里写题目描述 -->
|
8 | 8 |
|
9 |
| -<p>You are given a <strong>0-indexed</strong> <code>m x n</code> <strong>binary</strong> matrix <code>grid</code>. You can move from a cell <code>(row, col)</code> to any of the cells <code>(row + 1, col)</code> or <code>(row, col + 1)</code>.</p> |
| 9 | +<p>给定一个 <strong>下标从 0 开始</strong> 的 <code>m x n</code> 的 <strong>二进制</strong> 矩阵 <code>grid</code> ,从坐标为 <code>(row, col)</code> 的元素可以向右走 <code>(row, col+1)</code> 或向下走 <code>(row+1, col)</code> 。</p> |
10 | 10 |
|
11 |
| -<p>Return <code>true</code><em> if there is a path from </em><code>(0, 0)</code><em> to </em><code>(m - 1, n - 1)</code><em> that visits an <strong>equal</strong> number of </em><code>0</code><em>'s and </em><code>1</code><em>'s</em>. Otherwise return <code>false</code>.</p> |
| 11 | +<p>返回一个布尔值,表示从 <code>(0, 0)</code> 出发是否存在一条路径,经过 <strong>相同</strong> 数量的 <code>0</code> 和 <code>1</code>,到达终点 <code>(m-1, n-1)</code> 。如果存在这样的路径返回 <code>true</code> ,否则返回 <code>false</code> 。</p> |
12 | 12 |
|
13 | 13 | <p> </p>
|
14 |
| -<p><strong class="example">Example 1:</strong></p> |
| 14 | + |
| 15 | +<p><strong class="example">示例 1 :</strong></p> |
15 | 16 | <img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2500-2599/2510.Check%20if%20There%20is%20a%20Path%20With%20Equal%20Number%20of%200%27s%20And%201%27s/images/yetgriddrawio-4.png" />
|
16 | 17 | <pre>
|
17 |
| -<strong>Input:</strong> grid = [[0,1,0,0],[0,1,0,0],[1,0,1,0]] |
18 |
| -<strong>Output:</strong> true |
19 |
| -<strong>Explanation:</strong> The path colored in blue in the above diagram is a valid path because we have 3 cells with a value of 1 and 3 with a value of 0. Since there is a valid path, we return true. |
| 18 | +<b>输入:</b>grid = [[0,1,0,0],[0,1,0,0],[1,0,1,0]] |
| 19 | +<b>输出:</b>true |
| 20 | +<b>解释:</b>以上图中用蓝色标记的路径是一个有效的路径,因为路径上有 3 个值为 1 的单元格和 3 个值为 0 的单元格。由于存在一个有效的路径,因此返回 true 。 |
20 | 21 | </pre>
|
21 | 22 |
|
22 |
| -<p><strong class="example">Example 2:</strong></p> |
| 23 | +<p><strong class="example">示例 2 :</strong></p> |
23 | 24 | <img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2500-2599/2510.Check%20if%20There%20is%20a%20Path%20With%20Equal%20Number%20of%200%27s%20And%201%27s/images/yetgrid2drawio-1.png" style="width: 151px; height: 151px;" />
|
24 | 25 | <pre>
|
25 |
| -<strong>Input:</strong> grid = [[1,1,0],[0,0,1],[1,0,0]] |
26 |
| -<strong>Output:</strong> false |
27 |
| -<strong>Explanation:</strong> There is no path in this grid with an equal number of 0's and 1's. |
| 26 | +<b>输入:</b>grid = [[1,1,0],[0,0,1],[1,0,0]] |
| 27 | +<b>输出:</b>false |
| 28 | +<b>解释:</b>这个网格中没有一条路径经过相等数量的0和1。 |
28 | 29 | </pre>
|
29 | 30 |
|
30 | 31 | <p> </p>
|
31 |
| -<p><strong>Constraints:</strong></p> |
| 32 | + |
| 33 | +<p><strong>提示:</strong></p> |
32 | 34 |
|
33 | 35 | <ul>
|
34 | 36 | <li><code>m == grid.length</code></li>
|
35 | 37 | <li><code>n == grid[i].length</code></li>
|
36 | 38 | <li><code>2 <= m, n <= 100</code></li>
|
37 |
| - <li><code>grid[i][j]</code> is either <code>0</code> or <code>1</code>.</li> |
| 39 | + <li><code>grid[i][j]</code> 不是 <code>0</code> 就是 <code>1</code> 。</li> |
38 | 40 | </ul>
|
39 | 41 |
|
40 | 42 | ## 解法
|
|
0 commit comments