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 71ff2c9

Browse files
Merge pull request #50 from jaewon1676/main
2022. 5. 2(월) jaewon1676 3문제의 풀이 추가
2 parents 127533a + fb1f9b8 commit 71ff2c9

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

‎level-1/가운데-글자-가져오기.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,14 @@ function solution(s) {
3737
: s[s.length / 2 - 1] + s[s.length / 2];
3838
}
3939

40-
40+
// 정답 5 - jaewon1676
41+
function solution(s) {
42+
var answer = '';
43+
44+
if (s.length % 2 == 0 ) { // 짝수일 경우,
45+
answer = s[s.length / 2 - 1] + s[s.length / 2];
46+
} else {
47+
answer = s[parseInt(s.length / 2)]; // 홀수일 경우
48+
}
49+
return answer;
50+
}

‎level-1/정수-제곱근-판별.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ function solution(n) {
2222
// 아니라면 -1 반환
2323
return -1;
2424
}
25+
26+
//정답 4 - jaewon1676
27+
function solution(n) {
28+
let s = parseInt(Math.sqrt(n)) // n의 제곱근을 확인
29+
if (s ** 2 === n) return ((s+1) ** 2)
30+
31+
return -1;
32+
}

‎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 によって変換されたページ (->オリジナル) /