package leetcode;

/**
 * https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation/
 */
public class Problem1886 {
    public boolean findRotation(int[][] mat, int[][] target) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem1886 prob = new Problem1886();
        System.out.println(prob.findRotation(new int[][]{
            {0, 1},
            {1, 0}
        }, new int[][]{
            {1, 0},
            {0, 1}
        })); // true
        System.out.println(prob.findRotation(new int[][]{
            {0, 1},
            {1, 1}
        }, new int[][]{
            {1, 0},
            {0, 1}
        })); // false
        System.out.println(prob.findRotation(new int[][]{
            {0, 0, 0},
            {0, 1, 0},
            {1, 1, 1}
        }, new int[][]{
            {1, 1, 1},
            {0, 1, 0},
            {0, 0, 0}
        })); // true
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -235,243 +235,280 @@
     
-// TODO%0A        return false;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1886 prob = new Problem1886();%0A        System.out.println(prob.findRotation(new int%5B%5D%5B%5D%7B%0A            %7B0, 1%7D,%0A            %7B1, 0%7D%0A        %7D,
+for (int i = 0; i %3C 4; i++) %7B%0A            rotate(mat);%0A            if (isEqual(mat, target)) %7B%0A                return true;%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A%0A    private static void rotate(int%5B%5D%5B%5D mat) %7B%0A        int n = mat.length;%0A        int%5B%5D%5B%5D tmp =
  new
@@ -504,36 +504,38 @@
 %5D tmp = new int%5B
+n
 %5D%5B
-%5D%7B
+n%5D;
 %0A            %7B1,
@@ -531,156 +531,185 @@
     
-    %7B1, 0%7D,%0A            %7B0, 1%7D%0A        %7D)); // true%0A        System.out.println(prob.findRotation(new int%5B%5D%5B%5D%7B%0A            %7B0, 1%7D,%0A            %7B1, 1%7D
+for (int row = 0; row %3C n; row++) %7B%0A            for (int col = 0; col %3C n; col++) %7B%0A                tmp%5Brow%5D%5Bcol%5D = mat%5Brow%5D%5Bcol%5D;%0A            %7D%0A        %7D%0A        int c = n - 1;
 %0A   
@@ -709,38 +709,58 @@
  1;%0A        
-%7D, new int%5B%5D%5B%5D
+for (int row = 0; row %3C n; row++) 
 %7B%0A          
@@ -765,15 +765,18 @@
     
-%7B1, 0%7D,
+int r = 0;
 %0A   
@@ -788,94 +788,88 @@
     
-%7B0, 1%7D%0A        %7D)); // false%0A        System.out.println(prob.findRotation(new int%5B%5D%5B%5D%7B
+for (int col = 0; col %3C n; col++) %7B%0A                mat%5Br++%5D%5Bc%5D = tmp%5Brow%5D%5Bcol%5D;
 %0A   
@@ -881,18 +881,9 @@
     
-%7B0, 0, 0%7D,
+%7D
 %0A   
@@ -895,113 +895,225 @@
     
-%7B0, 1, 0%7D,
+c--;%0A        %7D
 %0A    
+%7D%0A%0A
     
-    %7B1, 1, 1%7D%0A        %7D, new int%5B%5D%5B%5D%7B%0A            %7B1, 1, 1%7D,%0A            %7B0, 1, 0%7D,%0A  
+private static boolean isEqual(int%5B%5D%5B%5D mat1, int%5B%5D%5B%5D mat2) %7B%0A        for (int i = 0; i %3C mat1.length; i++) %7B%0A            if (!Arrays.equals(mat1%5Bi%5D, mat2%5Bi%5D)) %7B%0A                return false;%0A
     
@@ -1122,16 +1122,10 @@
     
-%7B0, 0, 0
+  
 %7D%0A  
@@ -1135,19 +1135,29 @@
    %7D
-)); //
+%0A        return
  true
+;
 %0A   

Solve problem 1886