기록용 블로그

[프로그래머스][LV1] 바탕화면 정리 본문

개발/알고리즘 공부

[프로그래머스][LV1] 바탕화면 정리

andjane 2023. 4. 6. 00:53

 

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

숫자 갱신

package 프로그래머스.LV1;

public class pg3 {

    public static int[] solution(String[] wallpaper) {
        int lux = Integer.MAX_VALUE;
        int luy = Integer.MAX_VALUE;
        int rdx = Integer.MIN_VALUE;
        int rdy = Integer.MIN_VALUE;

        int wallpaperHeight = wallpaper.length;
        int wallpaperWidth = wallpaper[0].length();

        for(int i=0; i<wallpaperHeight; i++){
            for(int j=0; j<wallpaperWidth; j++){
                if(wallpaper[i].charAt(j) == '#'){
                    lux = Math.min(lux,i);
                    luy = Math.min(luy,j);
                    rdx = Math.max(rdx,i);
                    rdy = Math.max(rdy,j);
                }
            }
        }

        return new int[]{lux,luy,rdx+1,rdy+1};
    }
    public static void main(String args[]){
        String[] example = {".##...##.", "#..#.#..#", "#...#...#", ".#.....#.", "..#...#..", "...#.#...", "....#...."};
        int[] sol = solution(example);
        for(int i=0;i<sol.length;i++){
            System.out.println(sol[i]);
        }
    }
}

'개발 > 알고리즘 공부' 카테고리의 다른 글

[알고리즘] 시간복잡도  (0) 2023.04.20
[프로그래머스][LV1] 덧칠하기  (0) 2023.04.06
[프로그래머스][LV1] 공원 산책  (0) 2023.04.05
[BOJ1919] 애너그램 만들기  (0) 2023.04.05
[boj13223] 소금폭탄  (0) 2023.04.05