[JAVA 문제 풀이] 317. 바탕화면 정리

프로그래머스 (161990)
Stupefyee's avatar
Jun 13, 2025
[JAVA 문제 풀이] 317. 바탕화면 정리
notion image
notion image
 

내가 작성한 코드

class Solution { public int[] solution(String[] wallpaper) { int minRow = Integer.MAX_VALUE; // 최소 행 int minCol = Integer.MAX_VALUE; // 최소 열 int maxRow = Integer.MIN_VALUE; // 최대 행 int maxCol = Integer.MIN_VALUE; // 최대 열 for (int i = 0; i < wallpaper.length; i++) { String row = wallpaper[i]; for (int j = 0; j < row.length(); j++) { // '#' 문자를 찾으면 최소/최대 행과 열을 업데이트 if (row.charAt(j) == '#') { minRow = Math.min(minRow, i); maxRow = Math.max(maxRow, i + 1); minCol = Math.min(minCol, j); maxCol = Math.max(maxCol, j + 1); } } } return new int[]{minRow, minCol, maxRow, maxCol}; } }
Share article

stupefyee