KimMinJun
Coding Note
KimMinJun
전체 방문자
오늘
어제
  • 분류 전체보기 (486)
    • ALGORITHM (11)
      • 정렬 (6)
      • 최단경로 (1)
      • 자료구조 (1)
      • 슬라이딩 윈도우 (1)
      • etc (2)
    • Git (5)
    • Web (24)
      • Vanilla JS (13)
      • TS (2)
      • React (7)
      • ETC (1)
    • React 공식문서 (번역, 공부) (11)
      • Quick Start (2)
      • Installation (0)
      • Describing the UI (9)
      • Adding Interactivity (0)
      • Managing State (0)
      • Escape Hatches (0)
    • Next.js 공식문서 (번역, 공부) (3)
      • Getting Started (2)
      • Building Your Application (1)
    • PS (431)
      • 백준 (187)
      • Programmers (104)
      • CodeUp (21)
      • STL (3)
      • 제코베 JS 100제 (50)
      • SWEA (0)
      • LeetCode (65)
    • IT (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • 관리

공지사항

인기 글

태그

  • recursion
  • 수학
  • 그래프
  • Level 0
  • Level 1
  • 백준
  • Level1
  • js
  • LeetCode
  • codeup
  • 다이나믹 프로그래밍
  • C
  • tree
  • 문자열
  • Level 2
  • C++
  • 제코베 JS 100제
  • programmers
  • 정렬
  • string

최근 댓글

최근 글

hELLO · Designed By 정상우.
KimMinJun

Coding Note

PS/LeetCode

LeetCode / Matrix / 2352번 / Equal Row and Column Pairs / JS

2023. 6. 17. 13:52

< 문제 바로가기 >

 

Equal Row and Column Pairs - LeetCode

Can you solve this real interview question? Equal Row and Column Pairs - Given a 0-indexed n x n integer matrix grid, return the number of pairs (ri, cj) such that row ri and column cj are equal. A row and column pair is considered equal if they contain th

leetcode.com

 

< 문제 간단설명 >

각 행과 각 열을 모두 나누어서 봤을 때, 행과 열을 이루는 값들이 같으면 카운트를 하나 더해서 최종 카운트를 반환하는 문제이다.

 

/**
 * @param {number[][]} grid
 * @return {number}
 */
var equalPairs = function (grid) {
  let rowList = [];
  let colList = [];

  for (let i = 0; i < grid.length; i += 1) {
    let row = '';
    let col = '';

    for (let j = 0; j < grid.length; j += 1) {
      row += `${grid[i][j]} `;
      col += `${grid[j][i]} `;
    }

    rowList.push(row);
    colList.push(col);
  }

  let result = 0;
  for (let i = 0; i < grid.length; i += 1) {
    for (let j = 0; j < grid.length; j += 1) {
      if (rowList[i] === colList[j]) {
        result += 1;
      }
    }
  }

  return result;
};
저작자표시 (새창열림)

'PS > LeetCode' 카테고리의 다른 글

LeetCode / Tree / 1161번 / Maximum Level Sum of a Binary Tree / JS  (0) 2023.06.17
LeetCode / Tree / 530번 / Minimum Absolute Difference in BST / JS  (0) 2023.06.17
LeetCode / Array / 228번 / Summary Ranges / JS  (0) 2023.06.17
LeetCode / Design / 155번 / Min Stack / JS  (0) 2023.05.14
    'PS/LeetCode' 카테고리의 다른 글
    • LeetCode / Tree / 1161번 / Maximum Level Sum of a Binary Tree / JS
    • LeetCode / Tree / 530번 / Minimum Absolute Difference in BST / JS
    • LeetCode / Array / 228번 / Summary Ranges / JS
    • LeetCode / Design / 155번 / Min Stack / JS
    KimMinJun
    KimMinJun

    티스토리툴바