Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4aaf8a2

Browse files
Add 220502 멀쩡한 사각형.js
1 parent 63a25ea commit 4aaf8a2

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

‎level-2/멀쩡한-사각형.js‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,20 @@ let greatestCommonDivisor = (a, b) => {
3333
b = r;
3434
}
3535
return a;
36-
}
36+
}
37+
38+
//정답 3 - jaewon1676
39+
// 유클리드 호제법을 이용한 최대 공약수 구하기
40+
function gcd(w, h) {
41+
let mod = w % h; // w와 h의 나머지를 구합니다.
42+
43+
if (mod === 0) { // 나머지가 0일 경우 h를 반환합니다.
44+
return h;
45+
}
46+
// 만약 0이 아닐경우 w에 h를 넣고 h에 나머지인 mod를 넣어 해당 함수를 다시 호출해 줍니다.
47+
return gcd(h, mod);
48+
}
49+
function solution(w, h) {
50+
const gcdVal = gcd(w, h); // 최대 공약수를 구해줍니다.
51+
return w * h - (w + h - gcdVal);
52+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /