-
Notifications
You must be signed in to change notification settings - Fork 27
이예빈 / 주중8B / 4주차 #421
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
base: 주중8B
Are you sure you want to change the base?
The head ref may contain hidden characters: "\uC8FC\uC9118B"
이예빈 / 주중8B / 4주차 #421
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** | ||
| 채점을 시작합니다. | ||
| 정확성 테스트 | ||
| 테스트 1 〉 통과 (0.04ms, 33.4MB) | ||
| 테스트 2 〉 통과 (0.04ms, 33.4MB) | ||
| 테스트 3 〉 통과 (0.12ms, 33.4MB) | ||
| 테스트 4 〉 통과 (0.05ms, 33.4MB) | ||
| 테스트 5 〉 통과 (0.14ms, 33.4MB) | ||
| 테스트 6 〉 통과 (0.12ms, 33.4MB) | ||
| 테스트 7 〉 통과 (0.27ms, 33.5MB) | ||
| 테스트 8 〉 통과 (0.22ms, 33.4MB) | ||
| 테스트 9 〉 통과 (0.22ms, 33.4MB) | ||
| 테스트 10 〉 통과 (0.26ms, 33.6MB) | ||
| 테스트 11 〉 통과 (0.16ms, 33.5MB) | ||
| 테스트 12 〉 통과 (0.20ms, 33.5MB) | ||
| 테스트 13 〉 통과 (4.77ms, 39MB) | ||
| 테스트 14 〉 통과 (4.71ms, 38.9MB) | ||
| 채점 결과 | ||
| 정확성: 100.0 | ||
| 합계: 100.0 / 100.0 | ||
| */ | ||
|
|
||
| //첫 번째 시도 - 런타임에러(13, 14) | ||
| // -> 재귀함수는 호출이 가능한 깊이가 정해져있는데 | ||
| // 13, 14번은 테스트 케이스는 그 깊이를 초과했기 때문에 | ||
| // 런타임 에러가 뜨는 것이다. | ||
| function solution(n) { | ||
| let fibArr = [0, 1]; | ||
| const fib = (num) => { | ||
| if (fibArr[num] !== undefined) return fibArr[num]; | ||
| fibArr[num] = (fib(num - 1) + fib(num - 2)) % 1234567; | ||
| return fibArr[num]; | ||
| }; | ||
| return fib(n); | ||
| } | ||
|
|
||
| //두 번째 시도 - 통과 | ||
| function solution(n) { | ||
| let fibArr = [0, 1]; | ||
| if (n <= 1) return fibArr[n]; | ||
| for (let i = 2; i < n + 1; i++) { | ||
| fibArr.push((fibArr[i - 2] + fibArr[i - 1]) % 1234567); | ||
| } | ||
| return fibArr[n]; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /** | ||
| 채점을 시작합니다. | ||
| 정확성 테스트 | ||
| 테스트 1 〉 통과 (0.05ms, 33.4MB) | ||
| 테스트 2 〉 통과 (0.04ms, 33.4MB) | ||
| 테스트 3 〉 통과 (0.05ms, 33.5MB) | ||
| 테스트 4 〉 통과 (0.04ms, 33.4MB) | ||
| 테스트 5 〉 통과 (0.05ms, 33.5MB) | ||
| 테스트 6 〉 통과 (0.05ms, 33.6MB) | ||
| 테스트 7 〉 통과 (0.05ms, 33.4MB) | ||
| 테스트 8 〉 통과 (0.04ms, 33.6MB) | ||
| 테스트 9 〉 통과 (0.06ms, 33.6MB) | ||
| 테스트 10 〉 통과 (0.06ms, 33.5MB) | ||
| 테스트 11 〉 통과 (0.05ms, 33.6MB) | ||
| 테스트 12 〉 통과 (0.05ms, 33.5MB) | ||
| 테스트 13 〉 통과 (0.04ms, 33.4MB) | ||
| 테스트 14 〉 통과 (0.06ms, 33.5MB) | ||
| 효율성 테스트 | ||
| 테스트 1 〉 통과 (0.08ms, 32.9MB) | ||
| 테스트 2 〉 통과 (0.05ms, 33.4MB) | ||
| 테스트 3 〉 통과 (0.04ms, 33.3MB) | ||
| 테스트 4 〉 통과 (0.05ms, 33.5MB) | ||
| 테스트 5 〉 통과 (0.06ms, 33.4MB) | ||
| 테스트 6 〉 통과 (0.07ms, 33MB) | ||
| 채점 결과 | ||
| 정확성: 70.0 | ||
| 효율성: 30.0 | ||
| 합계: 100.0 / 100.0 | ||
| */ | ||
|
|
||
| function solution(n) { | ||
| const binaryN = n.toString(2); | ||
| let result = (n + 1).toString(2); | ||
| let i = n + 2; | ||
| while (result.split("1").length - 1 !== binaryN.split("1").length - 1) { | ||
| result = i.toString(2); | ||
| i++; | ||
| } | ||
| return parseInt(result, 2); | ||
| } | ||
|
|
||
| //다른 사람의 풀이 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다른사람풀이 잘 안봤었는데 저도 보는 습관을 좀 들여야 겠어요 |
||
| function solution(n, a = n + 1) { | ||
| return n.toString(2).match(/1/g).length == a.toString(2).match(/1/g).length | ||
| ? a | ||
| : solution(n, a + 1); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| 채점을 시작합니다. | ||
| 정확성 테스트 | ||
| 테스트 1 〉 통과 (0.04ms, 33.4MB) | ||
| 테스트 2 〉 통과 (0.05ms, 33.5MB) | ||
| 테스트 3 〉 통과 (0.04ms, 33.4MB) | ||
| 테스트 4 〉 통과 (0.04ms, 33.4MB) | ||
| 테스트 5 〉 통과 (0.04ms, 33.4MB) | ||
| 테스트 6 〉 통과 (0.04ms, 33.5MB) | ||
| 테스트 7 〉 통과 (0.03ms, 33.4MB) | ||
| 테스트 8 〉 통과 (0.03ms, 33.5MB) | ||
| 테스트 9 〉 통과 (0.04ms, 33.4MB) | ||
| 테스트 10 〉 통과 (0.03ms, 33.4MB) | ||
| 테스트 11 〉 통과 (0.03ms, 33.4MB) | ||
| 테스트 12 〉 통과 (0.23ms, 33.6MB) | ||
| 테스트 13 〉 통과 (0.04ms, 33.5MB) | ||
| 테스트 14 〉 통과 (0.04ms, 33.5MB) | ||
| 채점 결과 | ||
| 정확성: 100.0 | ||
| 합계: 100.0 / 100.0 | ||
| */ | ||
|
|
||
| function solution(a, b, n) { | ||
| let now = n; // 내가 가진 병 개수 | ||
| let count = 0; // 지금까지 받은 전체 병 개수 | ||
| while (a <= now) { | ||
| const avail = now - (now % a); // 마트에 줄 수 있는 최대 병 개수 | ||
| const canGet = (avail * b) / a; // 이번에 마트에서 받을 수 있는 병 개수 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 비례식생각해서 이렇게 풀었어요~ |
||
| count += canGet; | ||
| now = now - avail + canGet; | ||
| } | ||
| return count; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| 채점을 시작합니다. | ||
| 정확성 테스트 | ||
| 테스트 1 〉 통과 (0.08ms, 33.5MB) | ||
| 테스트 2 〉 통과 (0.17ms, 32.9MB) | ||
| 테스트 3 〉 통과 (0.17ms, 33MB) | ||
| 테스트 4 〉 통과 (0.08ms, 33.5MB) | ||
| 테스트 5 〉 통과 (0.18ms, 33.4MB) | ||
| 테스트 6 〉 통과 (0.07ms, 33.5MB) | ||
| 테스트 7 〉 통과 (0.18ms, 33.4MB) | ||
| 테스트 8 〉 통과 (0.08ms, 33.4MB) | ||
| 테스트 9 〉 통과 (0.08ms, 33.5MB) | ||
| 테스트 10 〉 통과 (0.17ms, 33.5MB) | ||
| 테스트 11 〉 통과 (0.09ms, 33.5MB) | ||
| 테스트 12 〉 통과 (0.08ms, 33.5MB) | ||
| 테스트 13 〉 통과 (0.07ms, 33.4MB) | ||
| 테스트 14 〉 통과 (0.08ms, 33.4MB) | ||
| 테스트 15 〉 통과 (0.11ms, 33.6MB) | ||
| 테스트 16 〉 통과 (0.12ms, 33.4MB) | ||
| 테스트 17 〉 통과 (0.08ms, 33.4MB) | ||
| 테스트 18 〉 통과 (0.08ms, 33.6MB) | ||
| 테스트 19 〉 통과 (0.07ms, 33.4MB) | ||
| 테스트 20 〉 통과 (0.08ms, 33.5MB) | ||
| 채점 결과 | ||
| 정확성: 100.0 | ||
| 합계: 100.0 / 100.0 | ||
| */ | ||
|
|
||
| function solution(n, lost, reserve) { | ||
| // 본인 것만 있는 사람 'normal' | ||
| let arr = Array(n).fill("normal"); | ||
| // 도난 당한 사람 'lost' | ||
| for (let i = 0; i < lost.length; i++) { | ||
| arr[lost[i] - 1] = "lost"; | ||
| } | ||
| // 도난 당했지만 여벌 가져온 사람 'normal' | ||
| // 본인 것도 있고 여벌도 있는 사람 'reserve' | ||
| for (let i = 0; i < reserve.length; i++) { | ||
| arr[reserve[i] - 1] = arr[reserve[i] - 1] === "lost" ? "normal" : "reserve"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 객체로 풀었는데 배열로 풀어도 괜찮은것 같네요~! |
||
| } | ||
|
|
||
| // 본인이 'lost'이고 앞 사람이 'reserve'면 둘다 'normal'로 변경 | ||
| // 본인이 'lost'이고 뒷 사람이 'reserve'면 둘다 'normal'로 변경 | ||
| for (let i = 0; i < arr.length; i++) { | ||
| if (arr[i] === "lost" && arr[i - 1] === "reserve") { | ||
| arr[i] = "normal"; | ||
| arr[i - 1] = "normal"; | ||
| } else if (arr[i] === "lost" && arr[i + 1] === "reserve") { | ||
| arr[i] = "normal"; | ||
| arr[i + 1] = "normal"; | ||
| } | ||
| } | ||
| return arr.filter((el) => el !== "lost").length; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
재귀가아닌 반복문으로 잘해결하신것 같습니다~