package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.com/problems/shift-2d-grid/
 */
public class Problem1260 {
    public List<List<Integer>> shiftGrid(int[][] grid, int k) {
        int m = grid.length;
        int n = m > 0 ? grid[0].length : 0;
        List<List<Integer>> answer = new ArrayList<>();
        // TODO:
        return answer;
    }

    public static void main(String[] args) {
        Problem1260 prob = new Problem1260();
        System.out.println(prob.shiftGrid(new int[][]{
            {1, 2, 3},
            {4, 5, 6},
            {7, 8, 9}
        }, 1)); // [[9,1,2],[3,4,5],[6,7,8]]
        System.out.println(prob.shiftGrid(new int[][]{
            {3, 8, 1, 9},
            {19, 7, 2, 5},
            {4, 6, 11, 10},
            {12, 0, 21, 13}
        }, 4)); // [[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]
        System.out.println(prob.shiftGrid(new int[][]{
            {1, 2, 3},
            {4, 5, 6},
            {7, 8, 9}
        }, 9)); // [[1,2,3],[4,5,6],[7,8,9]]
    }
}

@@ -224,16 +224,21 @@
    int m
+axRow
  = grid.
@@ -261,13 +261,23 @@
 int 
-n = m
+maxCol = maxRow
  %3E 0
@@ -311,192 +311,298 @@
     
-List%3CList%3CInteger%3E%3E answer = new ArrayList%3C%3E();%0A        // TODO:%0A        return answer
+for (int shift = 0; shift %3C k; shift++) %7B%0A            int%5B%5D%5B%5D tmp = new int%5BmaxRow%5D%5BmaxCol%5D;%0A            // the last column%0A            tmp%5B0%5D%5B0%5D = grid%5BmaxRow - 1%5D%5BmaxCol - 1%5D
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1260 prob = new Problem1260()
+    for (int row = 0; row %3C maxRow - 1; row++) %7B%0A                tmp%5Brow + 1%5D%5B0%5D = grid%5Brow%5D%5BmaxCol - 1%5D
 ;%0A  
@@ -611,566 +611,600 @@
     
+ 
-System.out.println(prob.shiftGrid(new int%5B%5D%5B%5D%7B%0A            %7B1, 2, 3%7D,%0A            %7B4, 5, 6%7D,%0A            %7B7, 8, 9%7D%0A        %7D, 1)); // %5B%5B9,1,2%5D,%5B3,4,5%5D,%5B6,7,8%5D%5D%0A        System.out.println(prob.shiftGrid(new int%5B%5D%5B%5D%7B%0A            %7B3, 8, 1, 9%7D,%0A            %7B19, 7, 2, 5%7D,%0A            %7B4, 6, 11, 10%7D,%0A            %7B12, 0, 21, 13%7D%0A        %7D, 4)); // %5B%5B12,0,21,13%5D,%5B3,8,1,9%5D,%5B19,7,2,5%5D,%5B4,6,11,10%5D%5D%0A        System.out.println(prob.shiftGrid(new int%5B%5D%5B%5D%7B%0A            %7B1, 2, 3%7D,%0A            %7B4, 5, 6%7D,%0A            %7B7, 8, 9%7D%0A        %7D, 9)); // %5B%5B1,2,3%5D,%5B4,5,6%5D,%5B7,8,9%5D%5D
+   %7D%0A            // shift all the columns%0A            for (int row = 0; row %3C maxRow; row++) %7B%0A                for (int col = maxCol - 1; col %3E 0; col--) %7B%0A                    tmp%5Brow%5D%5Bcol%5D = grid%5Brow%5D%5Bcol - 1%5D;%0A                %7D%0A            %7D%0A%0A            grid = tmp;%0A        %7D%0A        List%3CList%3CInteger%3E%3E answer = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C maxRow; i++) %7B%0A            List%3CInteger%3E list = new ArrayList%3C%3E();%0A            for (int j = 0; j %3C maxCol; j++) %7B%0A                list.add(grid%5Bi%5D%5Bj%5D);%0A            %7D%0A            answer.add(list);%0A        %7D%0A        return answer;
 %0A   

Solve problem 1260