-
Notifications
You must be signed in to change notification settings - Fork 98
문제 풀이 추가 #65
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
문제 풀이 추가 #65
Changes from 3 commits
4ab0ba6
f254aa5
e8bb651
05f6972
459591e
7d3d17a
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,13 @@ | ||
function isPrime(number) { | ||
|
||
if (number < 2) return false; | ||
for (let i = 2; i * i <= number; i += 1) { | ||
if (number % i === 0) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
function solution(n, k) { | ||
return (n).toString(k).split('0').filter((number) => isPrime(+number)).length; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function convertString(m) { | ||
|
||
return m | ||
.replace(/C#/g, 'c') | ||
.replace(/D#/g, 'd') | ||
.replace(/F#/g, 'f') | ||
.replace(/G#/g, 'g') | ||
.replace(/A#/g, 'a'); | ||
} | ||
|
||
function solution(m, musicinfos) { | ||
const listenSound = convertString(m); | ||
|
||
const map = new Map(); | ||
for (const info of musicinfos) { | ||
const [start, finish, title, _score] = info.split(','); | ||
const duration = ((+finish.slice(0, 2) * 60) + (+finish.slice(3, 5))) - ((+start.slice(0, 2) * 60) + (+start.slice(3, 5))); | ||
|
||
|
||
const score = convertString(_score); | ||
const playScore = score.repeat(Math.ceil(duration / score.length)).slice(0, duration); | ||
if (playScore.includes(listenSound)) { | ||
map.set(title, {score, playScore}); | ||
} | ||
} | ||
|
||
const filter = [...map.keys()].sort((a,b) => map.get(b).playScore.length - map.get(a).playScore.length); | ||
return filter.length >= 1 ? filter[0] : '(None)'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const DX = [-1, 1, 0, 0]; | ||
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. 해당 해설에도 주석 부탁드립니다! |
||
const DY = [0, 0, -1, 1]; | ||
|
||
function solution(grid) { | ||
const answer = []; | ||
const visited = Array.from({ length: grid.length }, () => []).map((v) => { | ||
for (let i = 0; i < grid[0].length; i += 1) { | ||
v.push(new Array(4).fill(false)); | ||
} | ||
return v | ||
}); | ||
|
||
for (let x = 0; x < grid.length; x += 1) { | ||
for (let y = 0; y < grid[0].length; y += 1) { | ||
for (let d = 0; d < 4; d += 1) { | ||
if (!visited[x][y][d]) { | ||
const stack = []; | ||
stack.push([x, y, d]); | ||
|
||
let cnt = 0; | ||
while (stack.length !== 0) { | ||
const [currentX, currentY, currentD] = stack.pop(); | ||
if (!visited[currentX][currentY][currentD]) { | ||
visited[currentX][currentY][currentD] = true; | ||
cnt += 1; | ||
|
||
const [nextX, nextY] = getNextXY(currentX, currentY, currentD, grid.length, grid[0].length); | ||
const nextD = getNextD(grid[nextX][nextY], currentD) | ||
|
||
stack.push([nextX, nextY, nextD]) | ||
} | ||
|
||
} | ||
answer.push(cnt); | ||
} | ||
} | ||
} | ||
} | ||
return answer.sort((a, b) => a - b); | ||
} | ||
|
||
|
||
function getNextXY(x, y, d, xLength, yLength) { | ||
x += DX[d]; | ||
y += DY[d]; | ||
|
||
if (x < 0) x = xLength - 1; | ||
if (x >= xLength) x = 0; | ||
if (y < 0) y = yLength - 1; | ||
if (y >= yLength) y = 0; | ||
|
||
return [x, y]; | ||
} | ||
|
||
function getNextD(command, d) { | ||
if (command === 'L') { | ||
d = [2, 3, 1, 0][d] | ||
} else if (command === 'R') { | ||
d = [3, 2, 0, 1][d] | ||
} | ||
return d | ||
} |