mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 19:18:14 +08:00
43 lines
1.7 KiB
HTML
43 lines
1.7 KiB
HTML
|
<p>在 <code>R</code> 行 <code>C</code> 列的矩阵上,我们从 <code>(r0, c0)</code> 面朝东面开始</p>
|
|||
|
|
|||
|
<p>这里,网格的西北角位于第一行第一列,网格的东南角位于最后一行最后一列。</p>
|
|||
|
|
|||
|
<p>现在,我们以顺时针按螺旋状行走,访问此网格中的每个位置。</p>
|
|||
|
|
|||
|
<p>每当我们移动到网格的边界之外时,我们会继续在网格之外行走(但稍后可能会返回到网格边界)。</p>
|
|||
|
|
|||
|
<p>最终,我们到过网格的所有 <code>R * C</code> 个空间。</p>
|
|||
|
|
|||
|
<p>按照访问顺序返回表示网格位置的坐标列表。</p>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>示例 1:</strong></p>
|
|||
|
|
|||
|
<pre><strong>输入:</strong>R = 1, C = 4, r0 = 0, c0 = 0
|
|||
|
<strong>输出:</strong>[[0,0],[0,1],[0,2],[0,3]]
|
|||
|
|
|||
|
<img alt="" src="https://aliyun-lc-upload.oss-cn-hangzhou.aliyuncs.com/aliyun-lc-upload/uploads/2018/08/24/example_1.png" style="height: 99px; width: 174px;">
|
|||
|
</pre>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>示例 2:</strong></p>
|
|||
|
|
|||
|
<pre><strong>输入:</strong>R = 5, C = 6, r0 = 1, c0 = 4
|
|||
|
<strong>输出:</strong>[[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,2],[4,1],[3,1],[2,1],[1,1],[0,1],[4,0],[3,0],[2,0],[1,0],[0,0]]
|
|||
|
|
|||
|
<img alt="" src="https://aliyun-lc-upload.oss-cn-hangzhou.aliyuncs.com/aliyun-lc-upload/uploads/2018/08/24/example_2.png" style="height: 142px; width: 202px;">
|
|||
|
</pre>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>提示:</strong></p>
|
|||
|
|
|||
|
<ol>
|
|||
|
<li><code>1 <= R <= 100</code></li>
|
|||
|
<li><code>1 <= C <= 100</code></li>
|
|||
|
<li><code>0 <= r0 < R</code></li>
|
|||
|
<li><code>0 <= c0 < C</code></li>
|
|||
|
</ol>
|