-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_2946.java
29 lines (27 loc) · 857 Bytes
/
_2946.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.fishercoder.solutions.thirdthousand;
import java.util.Arrays;
public class _2946 {
public static class Solution1 {
public boolean areSimilar(int[][] mat, int k) {
int m = mat.length;
int n = mat[0].length;
k %= n;
if (k == 0) {
return true;
}
int[][] updated = new int[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
// regardless i is even or odd, it's the same formula below!
updated[i][(j + k) % n] = mat[i][j];
}
}
for (int i = 0; i < m; i++) {
if (!Arrays.equals(mat[i], updated[i])) {
return false;
}
}
return true;
}
}
}