mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
28 lines
729 B
Java
28 lines
729 B
Java
|
class Solution {
|
||
|
public int equalPairs(int[][] grid) {
|
||
|
int count = 0, n = grid.length;
|
||
|
|
||
|
// Check each row r against each column c.
|
||
|
for (int r = 0; r < n; ++r) {
|
||
|
for (int c = 0; c < n; ++c) {
|
||
|
boolean match = true;
|
||
|
|
||
|
// Iterate over row r and column c.
|
||
|
for (int i = 0; i < n; ++i) {
|
||
|
if (grid[r][i] != grid[i][c]) {
|
||
|
match = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// If row r equals column c, increment count by 1.
|
||
|
if (match) {
|
||
|
count++;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return count;
|
||
|
}
|
||
|
}
|