Skip to content

[Algorithm] 카펫 #200

Description

@hwangJi-dev

💬 문제

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]{varres:[Int]=[]if yellow ==1{return[3,3]}foriin1...yellow /2+1{if yellow % i ==0{letyx= yellow / i
letans=(yx *2)+(i *2)+4if ans == brown {
res =[yx +2, i +2]break}}}return res
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions