Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Algorithm] 바탕화면 정리 #122

Closed
hwangJi-dev opened this issue Mar 3, 2023 · 0 comments
Closed

[Algorithm] 바탕화면 정리 #122

hwangJi-dev opened this issue Mar 3, 2023 · 0 comments

Comments

@hwangJi-dev
Copy link
Owner

hwangJi-dev commented Mar 3, 2023

💬 문제

바탕화면 정리


💬 Idea

  • 최소 좌표는 최소좌표대로, 최대 좌표는 최대 좌표대로 저장할 coordinate 변수를 만든다.
  • # 문자가 나올 시 coordinate의 0,1,2,3 인덱스에 min, max값을 비교하여 저장해준다.

💬 풀이

import Foundation

func solution(_ wallpaper:[String]) -> [Int] {
    var coordinate = [50, 50, 0, 0]
    
    for (idx, i) in wallpaper.enumerated() {
        for (jdx, j) in i.enumerated() {
            if j == "#" {
                coordinate[0] = min(idx, coordinate[0])
                coordinate[1] = min(jdx, coordinate[1])
                coordinate[2] = max(idx + 1, coordinate[2])
                coordinate[3] = max(jdx + 1, coordinate[3])
            }
        }
    }
    
    return coordinate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant