当前位置:网站首页>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;
}
}边栏推荐
猜你喜欢

阿里云技术专家秦隆:可靠性保障必备——云上如何进行混沌工程?

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

Visualize the training process using tensorboard

马斯克的“灵魂永生”:一半炒作,一半忽悠

【微服务~Sentinel】Sentinel降级、限流、熔断

Musk's "eternal soul": half hype, half flicker

水博士2

Brpc source code analysis (IV) -- bthread mechanism

NLP知识----pytorch,反向传播,预测型任务的一些小碎块笔记

Pytorch advanced training skills
随机推荐
Crawler crawls dynamic website
Fiddler抓包APP
【四】布局视图和布局工具条使用
Pytorch environment configuration and basic knowledge
Build a series of vision transformer practices, and finally meet, Timm library!
R语言ggplot2可视化:可视化散点图并为散点图中的部分数据点添加文本标签、使用ggrepel包的geom_text_repel函数避免数据点之间的标签互相重叠(为数据点标签添加线段、指定线段的角度
After having a meal with trump, I wrote this article
【5】 Page and print settings
面试官:“同学,你做过真实落地项目吗?”
【二】栅格数据显示拉伸色带(以DEM数据为例)
Web programming (II) CGI related
[micro service ~sentinel] sentinel degradation, current limiting, fusing
Intelligent information retrieval (overview of intelligent information retrieval)
【微服务~Sentinel】Sentinel降级、限流、熔断
PyTorch主要模块
微软Azure和易观分析联合发布《企业级云原生平台驱动数字化转型》报告
Eureka usage record
【九】坐标格网添加以及调整
Technical management essay
Behind the screen projection charge: iqiyi's quarterly profit, is Youku in a hurry?