99클럽 코테 스터디 26일차 - 완전탐색

김동하·2024년 8월 16일
0

알고리즘

목록 보기
75/90

문제

바탕화면 정리

풀이

  • 중첩 순회를 하면서 "#"를 찾으면 시작점과 끝점을 업데이트한다.

코드

lass Solution {
    public int[] solution(String[] wallpaper) {
        int startX = Integer.MAX_VALUE;
        int startY = Integer.MAX_VALUE;
        int endX = Integer.MIN_VALUE;
        int endY = Integer.MIN_VALUE;
        
        for(int i = 0; i < wallpaper.length; i++){
            for(int j = 0; j < wallpaper[0].length(); j++){
                if(wallpaper[i].charAt(j) == '#'){
                    startX = Math.min(startX, i);
                    startY = Math.min(startY, j);
                    endX = Math.max(endX, i+1);
                    endY = Math.max(endY, j+1);
                }
            }
        }
        return new int[]{startX, startY, endX, endY};
    }
}

정리

profile
프론트엔드 개발

0개의 댓글