Skip to content

Latest commit

 

History

History
61 lines (55 loc) · 949 Bytes

2352.相等行列对.md

File metadata and controls

61 lines (55 loc) · 949 Bytes

2352.相等行列对

/*
 * @lc app=leetcode.cn id=2352 lang=typescript
 *
 * [2352] 相等行列对
 */

// @lc code=start
function equalPairs(grid: number[][]): number {}
// @lc code=end

解法 1: 模拟

function equalPairs(grid: number[][]): number {
  const n = grid.length
  let res = 0
  for (let i = 0; i < n; i++) {
    next: for (let j = 0; j < n; j++) {
      for (let k = 0; k < n; k++) {
        if (grid[i][k] !== grid[k][j]) continue next
      }
      res++
    }
  }
  return res
}

Case

test.each([
  {
    input: {
      grid: [
        [3, 2, 1],
        [1, 7, 6],
        [2, 7, 7],
      ],
    },
    output: 1,
  },
  {
    input: {
      grid: [
        [3, 1, 2, 2],
        [1, 4, 4, 5],
        [2, 4, 2, 2],
        [2, 4, 2, 2],
      ],
    },
    output: 3,
  },
])('input: grid = $input.grid', ({ input: { grid }, output }) => {
  expect(equalPairs(grid)).toEqual(output)
})