[LeetCode] 492. Construct the Rectangle

Chobby·2025년 4월 6일
1

LeetCode

목록 보기
335/427

😎풀이

  1. w: 요소의 너비, 면적과 절댓값의 차이가 적어야 하므로 제곱근부터 계산
  2. area / w가 0일 때까지 반복하며 적절한 w 탐색
  3. 면적 및 너비 반환
function constructRectangle(area: number): number[] {
    let w = Math.floor(Math.sqrt(area))
    while(area % w !== 0) w--
    return [area / w, w]
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글