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

Browse files
Merge pull request #63 from yongchanson/main
[정기적 문제 풀이] 220602 풀이추가(2문제), 기존코드수정(1문제)
2 parents f9a74cb + f201787 commit 71a39e5

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

‎level-2/JadenCase-문자열-만들기.js‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,17 @@ function solution(s) {
2121
// .map((el, index) => index == 0 ? el.toUpperCase() : el.toLowerCase())
2222
// 덩어리의 요소가 첫번째이면 대문자, 그렇지 않으면 소문자로 변환 해줍니다.
2323
// .join('') 작은 배열들을 합쳐줍니다.
24-
// .join(' ') 큰 배열들을 합쳐줍니다.
24+
// .join(' ') 큰 배열들을 합쳐줍니다.
25+
26+
//정답 3 - yongchanson
27+
function solution(s) {
28+
let answer = [];
29+
s = s.split(" ");
30+
31+
for (let i = 0; i < s.length; i++) {
32+
answer.push(
33+
s[i].substring(0, 1).toUpperCase() + s[i].substring(1).toLowerCase()
34+
);
35+
}
36+
return answer.join(" ");
37+
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ let greatestCommonDivisor = (a, b) => {
2020
//정답 2 - codeisneverodd
2121
function solution(w, h) {
2222
var answer = 1;
23-
const gcd = greatestCommonDivisor(w, h)
23+
const gcd = greatestCommonDivisor2(w, h)
2424
const erasedBoxInUnit = h / gcd + w / gcd - 1
2525
answer = w * h - erasedBoxInUnit * gcd
2626
return answer;
2727
}
2828

29-
let greatestCommonDivisor = (a, b) => {
29+
let greatestCommonDivisor2 = (a, b) => {
3030
while (b > 0) {
3131
let r = a % b;
3232
a = b;
@@ -50,3 +50,16 @@ function solution(w, h) {
5050
const gcdVal = gcd(w, h); // 최대 공약수를 구해줍니다.
5151
return w * h - (w + h - gcdVal);
5252
}
53+
54+
//정답 4 - yongchanson
55+
function solution(w,h){
56+
const slope = h / w;
57+
let cnt = 0;
58+
//대각선 아래에 위치한 도형의 개수를 구합니다.
59+
//대각선과 만나는 도형을 포함하기 위해 ceil을 사용합니다.
60+
for(let i = 1; i <= w; i++){
61+
cnt += Math.ceil(slope * i);
62+
}
63+
//대각선 위에 위치한 도형의 개수 * 2을 리턴합니다.
64+
return ((w*h - cnt) * 2);
65+
}

0 commit comments

Comments
(0)

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