알고리즘

프로그래머스)바탕화면 정리

1일1공부실천하자 2023. 3. 24. 20:31

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

 

프로그래머스

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

programmers.co.kr

 

 

def solution(wallpaper):
    answer = []
    top = 99
    left = 99
    
    bottom = -1
    right = -1
    
    for i in range(len(wallpaper)):
        for j in range(len(wallpaper[i])):
            if wallpaper[i][j] == '#':
                if top > i:
                    top = i
                    
                    
                if left > j:
                    left = j
                    
                if bottom < i:
                    bottom = i
                
                if right < j:
                    right = j
    
    # print(top,left,bottom,right)
    answer = [top,left,bottom+1,right+1]
                
    
    return answer

조금만 생각하면 풀이방법이 나오는 완전탐색 알고리즘이다.

 

처음엔 분할정복인줄 알았지만, 단 한번의 드래그에서 완전탐색임을 깨달았다.