当前位置:网站首页>2022.07.24 (lc_6125_equal row and column pairs)
2022.07.24 (lc_6125_equal row and column pairs)
2022-07-25 12:39:00 【Leeli9316】

Method : Violent solution
class Solution {
public int equalPairs(int[][] grid) {
int n = grid.length;
List<int[]> rows = new ArrayList<>();
List<int[]> cols = new ArrayList<>();
// That's ok
for (int[] row : grid) {
rows.add(row);
}
// Column
for (int i = 0; i < n; i++) {
int[] col = new int[n];
for (int j = 0; j < n; j++) {
col[j] = grid[j][i];
}
cols.add(col);
}
// Compare each row and column
int ans = 0;
for (int[] row : rows) {
for (int[] col : cols) {
boolean flag = true;
for (int i = 0; i < n; i++) {
if (row[i] != col[i]) {
flag = false;
break;
}
}
if (flag) {
ans++;
}
}
}
return ans;
}
}class Solution {
public int equalPairs(int[][] grid) {
int ans = 0;
int n = grid.length;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
boolean flag = true;
for (int k = 0; k < n; k++) {
if (grid[i][k] != grid[k][j]) {
flag = false;
break;
}
}
if (flag) {
ans++;
}
}
}
return ans;
}
}边栏推荐
- 【2】 Grid data display stretch ribbon (take DEM data as an example)
- 技术管理杂谈
- 请问一下,使用数据集成从postgreSQL导数据到Mysql数据库,有部分数据的字段中出现emoj
- 【十一】矢量、栅格数据图例制作以及调整
- Introduction to the scratch crawler framework
- Pairwise comparison of whether the mean values between R language groups are the same: pairwise hypothesis test of the mean values of multiple grouped data is performed using pairwise.t.test function
- R language Visual scatter diagram, geom using ggrep package_ text_ The rep function avoids overlapping labels between data points (set the min.segment.length parameter to inf and do not add label segm
- 防范SYN洪泛攻击的方法 -- SYN cookie
- 【五】页面和打印设置
- Ansible
猜你喜欢
随机推荐
R language Visual scatter diagram, geom using ggrep package_ text_ The rep function avoids overlapping labels between data points (set the min.segment.length parameter to inf and do not add label segm
水博士2
Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
[micro service ~sentinel] sentinel degradation, current limiting, fusing
交换机链路聚合详解【华为eNSP】
LeetCode 0133. 克隆图
Script set random user_ agent
keepalived实现mysql的高可用
【十】比例尺添加以及调整
Zuul gateway use
循环创建目录与子目录
Spirng @Conditional 条件注解的使用
Implementation of recommendation system collaborative filtering in spark
Cmake learning notes (II) generation and use of Library
2.1.2 application of machine learning
WPF project introduction 1 - Design and development of simple login page
技术管理杂谈
Table partition of MySQL
状态(State)模式
Pytorch visualization









