当前位置:网站首页>2022.07.24(LC_6125_相等行列对)
2022.07.24(LC_6125_相等行列对)
2022-07-25 11:45:00 【Leeli9316】

方法:暴力求解
class Solution {
public int equalPairs(int[][] grid) {
int n = grid.length;
List<int[]> rows = new ArrayList<>();
List<int[]> cols = new ArrayList<>();
//行
for (int[] row : grid) {
rows.add(row);
}
//列
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);
}
//每一行和每一列进行比较
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;
}
}边栏推荐
- Pytorch environment configuration and basic knowledge
- numpy初识
- Fault tolerant mechanism record
- Pytorch advanced training skills
- After having a meal with trump, I wrote this article
- 【十】比例尺添加以及调整
- 搭建Vision Transformer系列实践,终于见面了,Timm库!
- Numpy first acquaintance
- R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化点状条带图、设置palette参数配置不同水平数据点的颜色、设置add参数在点状条带图中添加均值标准差竖线
- 使用TensorBoard可视化训练过程
猜你喜欢

【微服务~Sentinel】Sentinel降级、限流、熔断
![[micro service ~sentinel] sentinel degradation, current limiting, fusing](/img/60/448c5f40af4c0937814c243bd7cb04.png)
[micro service ~sentinel] sentinel degradation, current limiting, fusing

PyTorch进阶训练技巧

Brpc source code analysis (IV) -- bthread mechanism

919. 完全二叉树插入器 : 简单 BFS 运用题

氢能创业大赛 | 国家能源局科技司副司长刘亚芳:构建高质量创新体系是我国氢能产业发展的核心

WPF project introduction 1 - Design and development of simple login page

给生活加点惊喜,做创意生活的原型设计师丨编程挑战赛 x 选手分享

Learning to pre train graph neural networks

MySQL exercise 2
随机推荐
Musk's "eternal soul": half hype, half flicker
919. 完全二叉树插入器 : 简单 BFS 运用题
【七】图层显示和标注
Script set random user_ agent
Location analysis of recording an online deadlock
RestTemplate与Ribbon简单使用
cmake 学习使用笔记(二)库的生成与使用
PyTorch主要模块
Mirror Grid
aaaaaaaaaaA heH heH nuN
Web programming (II) CGI related
R语言ggplot2可视化:可视化散点图并为散点图中的部分数据点添加文本标签、使用ggrepel包的geom_text_repel函数避免数据点之间的标签互相重叠(为数据点标签添加线段、指定线段的角度
Pytorch advanced training skills
Atomic atomic class
Build a series of vision transformer practices, and finally meet, Timm library!
Figure neural network for recommending system problems (imp-gcn, lr-gcn)
From cloud native to intelligent, in-depth interpretation of the industry's first "best practice map of live video technology"
scrapy爬虫爬取动态网站
1.1.1 welcome to machine learning
【11】 Production and adjustment of vector and grid data Legends