JAVA_프로그래머스_PCCE 기출문제 9번_이웃한 칸
JAVA_프로그래머스_PCCE 기출문제 9번_이웃한 칸 풀이 class Solution { // 상하좌우 방향 private static final int[] dw = {-1, 1, 0, 0}; private static final int[] dh = {0, 0, -1, 1}; public int solution(String[][] board, int h, int w) { // 특정 칸 기준으로 상하좌우 값을 비교한다. String targetColor = board[h][w]; // 기준 칸 색상 int cnt = 0; // 이웃 칸 개수 세기 int rows = board.length; // h int cols = board[0].length; // w // 상하좌우 인접 칸 검사 for(int i = 0; i < 4; i++){ int newRow = h + dw[i]; int newCol = w + dh[i]; // 범위 체크 if(newRow >= 0 && newRow <