mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-13 03:11:42 +08:00
65 lines
2.5 KiB
HTML
65 lines
2.5 KiB
HTML
<p>给你一个 <code>m x n</code> 的二维数组 <code>grid</code>,数组由 <strong>正整数</strong> 组成。</p>
|
||
|
||
<p>你的任务是以 <strong>之字形 </strong>遍历 <code>grid</code>,同时跳过每个 <strong>交替 </strong>的单元格。</p>
|
||
|
||
<p>之字形遍历的定义如下:</p>
|
||
|
||
<ul>
|
||
<li>从左上角的单元格 <code>(0, 0)</code> 开始。</li>
|
||
<li>在当前行中向 <strong>右</strong> 移动,直到到达该行的末尾。</li>
|
||
<li>下移到下一行,然后在该行中向 <strong>左</strong><em> </em>移动,直到到达该行的开头。</li>
|
||
<li>继续在行间交替向右和向左移动,直到所有行都被遍历完。</li>
|
||
</ul>
|
||
|
||
<p><strong>注意:</strong>在遍历过程中,必须跳过每个 <strong>交替 </strong>的单元格。</p>
|
||
|
||
<p>返回一个整数数组 <code>result</code>,其中包含按 <strong>顺序 </strong>记录的、且跳过交替单元格后的之字形遍历中访问到的单元格值。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong class="example">示例 1:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong> <span class="example-io">grid = [[1,2],[3,4]]</span></p>
|
||
|
||
<p><strong>输出:</strong> <span class="example-io">[1,4]</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/11/23/4012_example0.png" style="width: 200px; height: 200px;" /></strong></p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong> <span class="example-io">grid = [[2,1],[2,1],[2,1]]</span></p>
|
||
|
||
<p><strong>输出:</strong> <span class="example-io">[2,1,2]</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/11/23/4012_example1.png" style="width: 200px; height: 240px;" /></p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 3:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong> <span class="example-io">grid = [[1,2,3],[4,5,6],[7,8,9]]</span></p>
|
||
|
||
<p><strong>输出:</strong> <span class="example-io">[1,3,5,7,9]</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/11/23/4012_example2.png" style="width: 260px; height: 250px;" /></p>
|
||
</div>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>2 <= n == grid.length <= 50</code></li>
|
||
<li><code>2 <= m == grid[i].length <= 50</code></li>
|
||
<li><code>1 <= grid[i][j] <= 2500</code></li>
|
||
</ul>
|