Skip to content

[정기적 해설 추가] 2022-03-23, 2문제 #4

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
merged 3 commits into from
Mar 23, 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
12 changes: 11 additions & 1 deletion level-2/땅따먹기.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ function solution(land) {
/* 풀이 과정
1. land의 행만큼 반복문을 돌린다.
2. i행(두번째 행)부터 land.length - 1행(마지막 행)까지 본인 열을 제외한 나머지 열의 최댓값을 본인의 열에 더하여 누적한다.
3. 마지막까지 다 구하면 마지막 행에서 최대값을 반환한다.*/
3. 마지막까지 다 구하면 마지막 행에서 최대값을 반환한다.*/

//정답 2 - codeisneverodd
function solution(land) {
for (let rowIndex = 1; rowIndex < land.length; rowIndex++) {
for (let colIndex = 0; colIndex < land[0].length; colIndex++) {
land[rowIndex][colIndex] += Math.max(...land[rowIndex - 1].slice(0, colIndex), ...land[rowIndex - 1].slice(colIndex + 1))
}
}
return Math.max(...land[land.length - 1])
}
15 changes: 15 additions & 0 deletions level-2/예상-대진표.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd

function solution(n, a, b) {
let currentRound = 1;
const myNextNumber = (num) => Math.floor((num + 1) / 2)//내가 이긴경우 다음으로 가지게 될 번호
while (a !== b) { // a의 다음 번호가 b의 다음번호와 같아지면 끝난다.
if (myNextNumber(a) === myNextNumber(b)) break
a = myNextNumber(a)
b = myNextNumber(b)
currentRound++
}
return currentRound
}