PS

    백준 / 4195번 / 친구 네트워크 / JS

    https://www.acmicpc.net/problem/4195 풀이const fs = require('fs');const filePath = process.platform === 'linux' ? 0 : './input.txt';const input = fs.readFileSync(filePath).toString().trim().split('\n');const T = +input.shift();function* idGenerator() { let id = 0; while (true) { yield id++; }}class UnionFind { constructor() { this.parent = []; this.count = []; this.nameMap = new Ma..

    백준 / 16935번 / 배열 돌리기 3

    풀이const fs = require('fs');const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';// const filePath = process.platform === 'linux' ? '/dev/stdin' : 'BOJ/input.txt';const input = fs.readFileSync(filePath).toString().trim().split('\n');const [N, M, R] = input.shift().split(' ').map(Number);const opList = input.pop().split(' ').map(Number);let arr = input.map((row) => row.spli..

    백준 / 3190번 / 뱀 / JS

    풀이const fs = require('fs');const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';// const filePath = process.platform === 'linux' ? '/dev/stdin' : 'BOJ/input.txt';const input = fs.readFileSync(filePath).toString().trim().split('\n');let N, K, L;const snakeDirInfo = [];let snakeDirInfoIndex = 0;const APPLE = 1;const EMPTY = 0;const SNAKE = -1;let board;// 상, 우, 하, 좌const dr..

    Programmers / Level 3 / 단속카메라 / JS

    https://school.programmers.co.kr/learn/courses/30/lessons/42884 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제분석이 문제는 전형적인 구간 스케줄링 문제이다.여러 구간이 주어졌을 때, 모든 구간을 커버하는 최소한의 점을 찾는 것과 같다. 직관적인 접근법차량들의 경로를 구간으로 생각한다.겹치는 구간들은 하나의 카메라로 처리가 가능하다.겹치지 않는 구간들은 각각 별도의 카메라가 필요하다. 풀이핵심 아이디어: 진출 기점을 기준으로 정렬한 후, greedy하게 카메라 위치를 선택한다.function solution(routes) { routes.sort((a, b..

    Programmers / Level 3 / 정수 삼각형 / JS

    https://school.programmers.co.kr/learn/courses/30/lessons/43105 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 풀이function solution(triangle) { const height = triangle.length; const dp = Array.from({ length: height }, (_, i) => Array(i + 1)); dp[0][0] = triangle[0][0]; for (let i = 1; i 문제 자체는 간단하다.주어진 triangle 배열과 똑같은 형태의 배열을 선언해주고 dp로 풀었다.dp로 이전 행의 좌, 우를 비교해서..

    Programmers / Level 2 / 가장 큰 수 / JS

    https://school.programmers.co.kr/learn/courses/30/lessons/42746 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 풀이function solution(numbers) { const result = numbers .map(String) .sort((a, b) => (b + a).localeCompare(a + b)) .join(''); return result[0] === '0' ? '0' : result;}풀이는 정말 간단하고, 특히 sort 부분에는 정말 다양한 풀이가 있다.하지만, 여기서는 localeCompare를 사용했는데, 그 이유는 다..