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 f4e42b9

Browse files
codeisneveroddchaerin-devgithub-actionspereng11iHoHyeon
authored
[19주차] 풀이추가 (#83)
* solution: level 2 / 하노이 탑 풀이 추가 * solution: 모음사전 * solution 체육복 * solution 모의고사 * solution 위장 * solution 튜플 * 브랜치 흐름 정리 (#71) * docs: 커밋 컨벤션 수정 및 contributor 추가 * Automatic Update README.md * fix: 오타 수정 * docs: 커밋 컨벤션 변경 및 리드미 디자인 수정 * docs: 풀이 완료시점 수정 * Automatic Update README.md * docs: PR 템플릿 추가 Co-authored-by: github-actions <github-actions@github.com> * fix: base url 핫픽스 (#74) * docs: 커밋 컨벤션 수정 및 contributor 추가 * Automatic Update README.md * fix: 오타 수정 * docs: 커밋 컨벤션 변경 및 리드미 디자인 수정 * docs: 풀이 완료시점 수정 * Automatic Update README.md * docs: PR 템플릿 추가 * fix: 링크 base url 수정 (#73) * Automatic Update README.md Co-authored-by: github-actions <github-actions@github.com> * [손재영] level2 배달 풀이 및 주석 * solution 구명보트 * fix: 최소힙 클래스 바깥 분리&파일 컨벤션 적용 * solution level2 - 숫자 블록 (#79) * solution level2 - 숫자 블록 * Update level-2/숫자-블록.js Co-authored-by: codeisneverodd <codeisneverodd@gmail.com> Co-authored-by: codeisneverodd <codeisneverodd@gmail.com> * solution: level2 - 피로도 문제 풀이 * refactor: level2 - 피로도(가독성 개선) 1. 최대한 순수함수에 가깝도록, 함수 내부에서 외부 변수를 참조하거나 조작하지 않도록 수정하였습니다. 2. 변수와 함수 이름을 수정하여 의미를 명확히 하였습니다. 3. 로직의 목적을 쉽게 파악할 수 있도록 일반 for문 대신 배열 메서드를 적극 활용하였습니다. * feat: PR 템플릿 위치 변경 * feat: husky 및 pre-commit hook 설정, prettierignore 추가 * fix: 잘못 업로드된 해설 삭제 Co-authored-by: chaerin-dev <chaerin.dev@gmail.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Jaeyeong son <nardi0302@gmail.com> Co-authored-by: iHoHyeon <hyunee169@naver.com> Co-authored-by: iHoHyeon <74816327+iHoHyeon@users.noreply.github.com>
1 parent d00676a commit f4e42b9

File tree

9 files changed

+1788
-242
lines changed

9 files changed

+1788
-242
lines changed
File renamed without changes.

‎.github/workflows/update-README.yml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ on:
77
push:
88
branches:
99
- main
10-
- manage
1110
pull_request:
1211
branches:
1312
- main
14-
- manage
1513
jobs:
1614
build:
1715
runs-on: ubuntu-latest

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
README.md
23
# Created by https://www.toptal.com/developers/gitignore/api/macos,webstorm
34
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,webstorm
45

‎.prettierignore‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/node_modules
2+
.gitignore
3+
.prettierrc.json
4+
README.md
5+
/.github
6+
/.husky

‎README.md‎

Lines changed: 0 additions & 234 deletions
Large diffs are not rendered by default.

‎level-2/숫자-블록.js‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1 - iHoHyeon
4+
function solution(begin, end) {
5+
return new Array(end - begin + 1).fill(null).map((v, idx) => calc(begin + idx));
6+
// begin ~ end 각 위치에 대해서 calc 함수의 return 값으로 채운다.
7+
}
8+
9+
const calc = (number) => {
10+
if (number === 1) return 0;
11+
// 1번째 위치는 무조건 0블록이 위치
12+
13+
for (let i = 2; i <= Math.sqrt(number); i++) {
14+
if (number % i === 0 && number / i <= 10_000_000) return number / i;
15+
// 10_000_000번 블록까지만 놓았으므로 숫자를 초과하는 경우는 제외
16+
}
17+
18+
return 1;
19+
};
20+
21+
/*
22+
1번 블록부터 10_000_000번 블록까지 전부 규칙에 따라서 놓는 경우는
23+
시간 / 공간 복잡도가 급상승
24+
25+
-> 따라서 각 위치에 어떤 숫자의 블록이 놓일지를 계산해주자
26+
27+
-> n번째 위치에는 1, n을 제외한 n의 가장 큰 약수의 블록이 놓이게 된다.
28+
29+
-> 가장 큰 약수는 n / (n의 가장 작은 약수)임을 이용해서 계산해주면 된다.
30+
31+
+ 가장 큰 약수가 1인 경우는 소수인 경우이고 숫자 1 블록이 놓인다.
32+
*/

‎level-2/피로도.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1 - pereng11
4+
//완전 탐색, greedy O(N^2)
5+
function solution(currentFatigue, dungeons) {
6+
return getMaxCount(currentFatigue, 0, dungeons);
7+
}
8+
9+
function getMaxCount(currentFatigue, visitedCount, dungeons) {
10+
const possibleDungeons = dungeons.filter(([minNeededFatigue, _]) => minNeededFatigue <= currentFatigue);
11+
if (possibleDungeons.length === 0) return visitedCount;
12+
13+
const maxCount = possibleDungeons.reduce((prevCount, curr, currentIndex) => {
14+
const [_, usedFatigue] = curr;
15+
const nextDungeons = possibleDungeons.filter((_, index) => index !== currentIndex);
16+
const currentCount = getMaxCount(
17+
currentFatigue - usedFatigue,
18+
visitedCount + 1,
19+
nextDungeons
20+
);
21+
return Math.max(currentCount, prevCount);
22+
}, 0);
23+
24+
return maxCount;
25+
}
26+
27+
28+

0 commit comments

Comments
(0)

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