KotlinAlgorithm#19 (POG 바탕화면 정리)

박채빈·2023년 7월 19일
0

KotlinAlgorithm

목록 보기
19/28
post-thumbnail

POG 바탕화면 정리

링크

코드

class Solution {
    fun solution(wallpaper: Array<String>): IntArray {
        val answer = intArrayOf(wallpaper.size, wallpaper[0].length, 0, 0)

        wallpaper.forEachIndexed { rowIndex, rowItem ->
            rowItem.forEachIndexed { columnIndex, columnItem ->
                if (columnItem == '#') {
                    answer[0] = answer[0].coerceAtMost(rowIndex)
                    answer[1] = answer[1].coerceAtMost(columnIndex)
                    answer[2] = answer[2].coerceAtLeast(rowIndex + 1)
                    answer[3] = answer[3].coerceAtLeast(columnIndex + 1)
                }
            }
        }

        return answer
    }
}
profile
안드로이드 개발자

1개의 댓글

comment-user-thumbnail
2023년 7월 19일

이 글은 제게 많은 도움이 되었습니다.

답글 달기