Skip to content

Commit 7a446b3

Browse files
a-khakimova.khakimov
authored andcommitted
2352. Equal Row and Column Pairs
1 parent ace1f2d commit 7a446b3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object Solution {
2+
def equalPairs(grid: Array[Array[Int]]): Int = {
3+
val columns = grid.map(_.toList).toList
4+
val rows = grid.transpose.toList.map(_.toList)
5+
var answer: Int = 0
6+
rows.foreach { row => answer += columns.count(_ == row) }
7+
answer
8+
}
9+
}
10+
11+
Solution.equalPairs(Array(Array(3,2,1),Array(1,7,6),Array(2,7,7))) // 1
12+
Solution.equalPairs(Array(Array(3,1,2,2),Array(1,4,4,5),Array(2,4,2,2),Array(2,4,2,2))) // 3
13+
Solution.equalPairs(Array(Array(13, 13),Array(13, 13))) // 4

0 commit comments

Comments
 (0)