Skip to content

Commit 1e827f9

Browse files
committed
Added README.md file for Shift 2D Grid
1 parent 8d57004 commit 1e827f9

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

1386-shift-2d-grid/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<h2><a href="https://leetcode.com/problems/shift-2d-grid">Shift 2D Grid</a></h2> <img src='https://img.shields.io/badge/Difficulty-Easy-brightgreen' alt='Difficulty: Easy' /><hr><p>Given a 2D <code>grid</code> of size <code>m x n</code>&nbsp;and an integer <code>k</code>. You need to shift the <code>grid</code>&nbsp;<code>k</code> times.</p>
2+
3+
<p>In one shift operation:</p>
4+
5+
<ul>
6+
<li>Element at <code>grid[i][j]</code> moves to <code>grid[i][j + 1]</code>.</li>
7+
<li>Element at <code>grid[i][n - 1]</code> moves to <code>grid[i + 1][0]</code>.</li>
8+
<li>Element at <code>grid[m&nbsp;- 1][n - 1]</code> moves to <code>grid[0][0]</code>.</li>
9+
</ul>
10+
11+
<p>Return the <em>2D grid</em> after applying shift operation <code>k</code> times.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
<img alt="" src="https://assets.leetcode.com/uploads/2019/11/05/e1.png" style="width: 400px; height: 178px;" />
16+
<pre>
17+
<strong>Input:</strong> <code>grid</code> = [[1,2,3],[4,5,6],[7,8,9]], k = 1
18+
<strong>Output:</strong> [[9,1,2],[3,4,5],[6,7,8]]
19+
</pre>
20+
21+
<p><strong class="example">Example 2:</strong></p>
22+
<img alt="" src="https://assets.leetcode.com/uploads/2019/11/05/e2.png" style="width: 400px; height: 166px;" />
23+
<pre>
24+
<strong>Input:</strong> <code>grid</code> = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4
25+
<strong>Output:</strong> [[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]
26+
</pre>
27+
28+
<p><strong class="example">Example 3:</strong></p>
29+
30+
<pre>
31+
<strong>Input:</strong> <code>grid</code> = [[1,2,3],[4,5,6],[7,8,9]], k = 9
32+
<strong>Output:</strong> [[1,2,3],[4,5,6],[7,8,9]]
33+
</pre>
34+
35+
<p>&nbsp;</p>
36+
<p><strong>Constraints:</strong></p>
37+
38+
<ul>
39+
<li><code>m ==&nbsp;grid.length</code></li>
40+
<li><code>n ==&nbsp;grid[i].length</code></li>
41+
<li><code>1 &lt;= m &lt;= 50</code></li>
42+
<li><code>1 &lt;= n &lt;= 50</code></li>
43+
<li><code>-1000 &lt;= grid[i][j] &lt;= 1000</code></li>
44+
<li><code>0 &lt;= k &lt;= 100</code></li>
45+
</ul>

0 commit comments

Comments
 (0)