분류 전체보기

https://school.programmers.co.kr/learn/courses/30/lessons/49189코드function solution(n, edge) { // 그래프 구성 const graph = Array.from(new Array(n + 1), () => new Array()); for (const e of edge) { graph[e[0]].push(e[1]); graph[e[1]].push(e[0]); } // BFS let farthest_dist = 0; let farthest_nodes = new Set(); const q = [[1, 0]]; const visited = new Array(n + 1).fill(false); visited[1] = ..
https://school.programmers.co.kr/learn/courses/30/lessons/12979코드function solution(n, stations, w) { let answer = 0; stations.unshift(-w); stations.push(n + w + 1); for (let i = 0; i w * 2) { answer += Math.ceil((gap - w * 2) / (w * 2 + 1)); } } return answer;} 두 기지국의 사이(`gap`)가 w*2보다 크다면 그 사이에 추가로 기지국을 세워야 한다. 이 때 필요한 기지국의 개수는 커버되지 않는 범위의 길이인 `gap-w*2`를 하나의 기지국이 커버할 수 있는 길이인 `w*2..
https://school.programmers.co.kr/learn/courses/30/lessons/12985코드function solution(n,a,b){ if(a>b){ const temp = a a = b b = temp } let answer = 1; for(let i=0;i 번호가 n이었다면 다음 라운드로 넘어갔을 때의 번호는 n/2를 소수점 첫째자리에서 올림한 값과 같다는 사실만 알면 어렵지 않게 풀 수 있는 문제였다. a와 b의 다음 라운드 번호가 같아지는 순간을 구하면 그때가 둘이 맞붙는 라운드이다.
https://school.programmers.co.kr/learn/courses/30/lessons/64064코드function solution(user_id, banned_id) { let answer = new Set(); const get_pattern = (id) => { const transformed = id.replace(/\*/g, "."); return new RegExp(`^${transformed}$`); }; const check_banned = (pattern) => { return user_id.filter((id) => pattern.test(id)); }; const bt = (idx, banned_set) => { if (idx === b..
https://school.programmers.co.kr/learn/courses/30/lessons/43162코드3가지 버전으로 코드를 작성했다. 셋 다 정답 코드이다.양방향 큐를 이용한 BFSfunction solution(n, computers) { let answer = 0; const visited = new Array(n).fill(false); const bfs = (start)=>{ const q = [start]; visited[start] = true while(q.length>0){ const now = q.shift(); for(let i=0;i재귀를 이용한 DFSfunction solut..
딜레이레이
'분류 전체보기' 카테고리의 글 목록 (5 Page)