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] 카펫 #200

Closed
hwangJi-dev opened this issue Apr 13, 2023 · 0 comments
Closed

[Algorithm] 카펫 #200

hwangJi-dev opened this issue Apr 13, 2023 · 0 comments

Comments

@hwangJi-dev
Copy link
Owner

hwangJi-dev commented Apr 13, 2023

💬 문제

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


💬 Idea

  • 노란색을 직사각형으로 채울 수 있는 가로, 세로를 찾기 위해 반복문을 돌면서 나머지가 0인 경우를 찾는다.
  • 만약 (yx * 2) + (i * 2) + 4 가 브라운의 값과 같다면 target이므로 break한다.

💬 풀이

import Foundation

func solution(_ brown:Int, _ yellow:Int) -> [Int] {
    var res: [Int] = []
    
    if yellow == 1 {
        return [3, 3]
    }
    
    for i in 1...yellow / 2 + 1 {
        if yellow % i == 0 {
            let yx = yellow / i
            let ans = (yx * 2) + (i * 2) + 4
            
            if ans == brown {
                res = [yx + 2, i + 2]
                break
            }
        }
    }
    
    return res
}
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