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

2022. 5. 9(월) jaewon1676 4문제의 풀이 추가 #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
jaewon1676 merged 4 commits into codeisneverodd:main from jaewon1676:main
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion level-1/두-정수-사이의-합.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ function solution(a, b) {
//정답 4 - prove-ability
function solution(a, b) {
return Array.from({length: Math.max(a, b) - Math.min(a, b) + 1}, (_, i) => i + Math.min(a, b)).reduce((a, b) => a + b, 0);
}
}

//정답 5 - jaewon1676
function solution(a, b) {
if (b < a){ // b가 a보다 큰 수가 되도록 해준다.
let c = b
b = a
a = c
}
let sum = 0; // 합을 구할 변수
for (let i=a; i<=b; i++){
sum += i
}
return sum;
}
22 changes: 21 additions & 1 deletion level-1/소수-찾기.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,24 @@ function solution(n) {
}

return count;
}
}

//정답 4 - jaewon1676
function solution(n) {
let arr = [];

// 0과 1을 제외한 2부터 n까지 배열에 담아줍니다.
for(let i=2; i<=n; i++) {
arr[i] = i;
}
for(let i=2; i<=n; i++) { // 인덱스 2부터 반복문 돌면서 0이면 다시 다음 반복문을 돕니다.
if (arr[i] === 0) continue;

for(let j=i*2; j<=n; j+=i) { // 각 인덱스(i)의 배수들을 0으로 지정해줍니다.
arr[j] = 0;
}
}

// filter를 이용해 0이아닌 수들의 개수를 return합니다.
return arr.filter(v => v!==0).length;
}
21 changes: 21 additions & 0 deletions level-2/삼각-달팽이.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,24 @@ function solution(n) {
}
return snail.flatMap((num) => num);
}

//정답 2 - jaewon1676
function solution(n) {
const answer = new Array(n).fill().map((e, i) => new Array(i + 1));
// 이차원배열을 만들어준다

let count = 0;
let x = -1; // 행 , 0행 0열부터 시작해주기 위해 x는 -1 해줍니다.
let y = 0; // 열
while (n > 0) {
for (let i = 0; i < n; i++) answer[++x][y] = ++count; // 아래로 이동합니다.
for (let i = 0; i < n - 1; i++) answer[x][++y] = ++count; // 오른쪽으로 이동합니다.
for (let i = 0; i < n - 2; i++) answer[--x][--y] = ++count; // 대각선 오른쪽 위로 이동합니다.

n -= 3;
}
return answer.flatMap(e => e);
// flatMap은 이차원의 여러 배열을 하나의 배열로 묶어줍니다.
// ex [ [ 1 ], [ 2, 9 ], [ 3, 10, 8 ], [ 4, 5, 6, 7 ] ]
// => [1, 2, 9, 3, 10, 8, 4, 5, 6, 7]
}
21 changes: 20 additions & 1 deletion level-2/큰-수-만들기.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,23 @@ function solution(number, k) {
}
answer = answerStack.join('')
return answer;
}
}

//정답 4 - jaewon1676
function solution(number, k) {
const stack = [];
let answer = '';

for(let i=0; i<number.length; i++){
const el = number[i];
while(k > 0 && stack[stack.length-1] < el){
stack.pop();
k--;
}
stack.push(el);
}
stack.splice(stack.length-k, k);
answer = stack.join("");
return answer;
}

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