[프로그래머스] 바탕화면 정리 (JAVA)

유존돌돌이·2023년 3월 7일
0

Programmers

목록 보기
166/167
post-thumbnail

풀이

class Solution {
    public int[] solution(String[] wallpaper) {
        // 시작x, 시작y, 끝x, 끝y
        int lux=Integer.MAX_VALUE, luy=Integer.MAX_VALUE, rdx=0, rdy=0;
        for(int i=0 ; i<wallpaper.length ; i++) {
            String wp = wallpaper[i];
            for(int j=0 ; j<wallpaper[i].length() ; j++) {
                if(wp.charAt(j)=='#') {
                    lux = Math.min(lux, i);
                    luy = Math.min(luy, j);
                    rdx = Math.max(rdx, i+1);
                    rdy = Math.max(rdy, j+1);
                }
            }
        }
        return new int[]{lux, luy, rdx, rdy};
    }
}

시작점 : 파일이 있는 위치의 최소좌표
끝점 : 파일이 있는 위치의 최대좌표

프로그래머스 URL

https://school.programmers.co.kr/learn/courses/30/lessons/161990

0개의 댓글