일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 레벨 1
- 타입스크립트
- 프로그래머스
- 타입 챌린지
- ip
- 알고리즘
- 프로그래머스 레벨 2
- Node.js
- type challenge
- TCP
- dfs
- 그래프
- HTTP 완벽 가이드
- Crawling
- 수학
- Algorithm
- 문자열
- HTTP
- 자바스크립트
- 크롤링
- socket
- 가천대
- 쉬운 문제
- dp
- 소켓
- 백준
- BFS
- typescript
- Nestjs
- javascript
- Today
- Total
목록프로그래밍/알고리즘 풀이 (210)
kakasoo
// 백준 6603번 로또를 풀었습니다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const combinations = function* (elements, selectNumber) { for (let i = 0; i < elements.length; i++) { if (selectNumber === 1) { yield [elements[i]]; } else { const fixed = elements[i]; const rest = combinations(elements.slice(i + 1), selectNumber - ..
코드 중간 주석 부분을 확인할 것 // 백준 10971번 외판원 순회2를 풀었습니다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const input = []; const permutations = function* (elements) { if (elements.length === 1) { yield elements; } else { const [first, ...rest] = elements; for (const a of permutations(rest)) { for (let i = 0; i < elements.length..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let count; const input = []; let maxValue = -987654321; rl.on("line", (line) => { if (!count) { count = Number(line); } else { input.push(line); if (input.length === count) { main(); } } }); const getPermutations = function* (elements) { if (elements.length === 1) { yield..
// 백준 10819번 차이를 최대로를 풀었습니다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { if (isNaN(line)) { const permutation = [...permutations(line.split(" ").map(Number))]; const answer = []; for (let i = 0; i < permutation.length; i++) { let sum = 0; for (let j = 0; j < permutation[i].length - 1; j++)..
// 백준 10974번 모든 순열을 풀었습니다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { const elements = new Array(Number(line)).fill(0).map((el, i) => i + 1); const result = [...permutations(elements)].map((el) => el.join(" ")).sort(); for (const a of result) { console.log(a); } }); /** * * @param {number..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { const numPad = new Array(line.length).fill(0).map((el, i) => i + 1); const acc = numPad.map((el, i) => { if (10 ** (i + 1) < Number(line)) { return el * 10 ** i * 9; } else { return el * (Number(line) + 1 - 10 ** i); } }); const sum = acc.reduce(..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const input = []; rl.on("line", (line) => { input.push(line); }).on("close", () => { main(); }); /** * * @param {number} curNumber * @param {number[]} brokenButtons */ const checkNum = (curNumber, brokenButtons) => { const numbers = curNumber.toString().split("").map(Numb..
// 프로그래머스 레벨2 n진수 게임을 풀었습니다. // 제너레이터를 활용한 풀이 function* printNumbers(start, n) { for (let i = start; i { const iter = printNumbers(0, n); const answer = []; for (let i = 0; i < t * m; i++) { answer.push(iter.ne..
// 프로그래머스 레벨2 캐시를 풀었습니다. // 아예 LRU에 대한 개념이 없어서, (hit, miss 개념은 안다. ) // 곤란하게 한 문제다. const solution = (cacheSize, cities) => { if (cacheSize === 0) return cities.length * 5; const cache = []; let answer = 0; for (let i = 0; i < cities.length; i++) { const city = cities[i].toUpperCase(); if (cache.includes(city)) { answer += 1; cache.splice(cache.indexOf(city), 1); cache.push(city); } else { answe..
// 프로그래머스 레벨2 점프와 순간 이동을 풀었습니다. const solution = (n) => { // const visited = new Array(n + 1).fill(0).map((el, i) => i); // const dfs = (cur) => { // for (let i = 1; 2 ** i * cur el == 1).length; } dfs로 시간 초과가 떠서 bfs로 고치고, 최적화를 위해서 별 짓을 다 했는데도 시간 초과는 사라지지 않았다. 혹시 그래프적인 방법 외에도 뭔가 있나 고민해봤는데, 2로 나눴을 때의 나머지가 1인 횟수가 아무래도 답인 거 같다. 그래서 2진수로 변환하여 구했다.
// 프로그래머스 레벨 3 가장 먼 노드를 풀었습니다. const solution = (n, edge) => { const map = new Array(n + 1).fill(0); for (let i = 1; i { const [from, to] = el; map[from].push(to); map[to].push(from); }); const visited = new Array(n + 1).fill(0); visited[0] = -1; const bfs = (start) => { const queue = [start]; visited[start] = 1; while (queue.length) { con..
const solution = (dirs) => { const answer = []; let next = { y : 5, x : 5 }; dirs.split('').forEach((dir) => { const cur = next; const funcs = { "U" : function (cur) { return { y : cur.y + 1, x : cur.x }; }, "D" : function (cur) { return { y : cur.y - 1, x : cur.x }; }, "R" : function (cur) { return { y : cur.y, x : cur.x + 1 }; }, "L" : function (cur) { return { y : cur.y, x : cur.x - 1..