일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
- 백준
- Nestjs
- Node.js
- typescript
- BFS
- TCP
- Crawling
- Algorithm
- 문자열
- 타입스크립트
- 알고리즘
- 프로그래머스
- 가천대
- 타입 챌린지
- 자바스크립트
- HTTP 완벽 가이드
- javascript
- socket
- 레벨 1
- ip
- type challenge
- HTTP
- 소켓
- 수학
- dfs
- 그래프
- 쉬운 문제
- 크롤링
- 프로그래머스 레벨 2
- dp
- Today
- Total
목록javascript (104)
kakasoo
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..
const left = 0; const right = 1; const isRight = (arr) => { const stack = []; for (const item of arr) { stack.push(item); if (stack.length >= 2) { while ((stack[stack.length - 2] === '(' && stack[stack.length - 1] == ')') || (stack[stack.length - 2] === '[' && stack[stack.length - 1] == ']') || (stack[stack.length - 2] === '{' && stack[stack.length - 1] ==..
const checkArr = (arr) => { const firstValue = arr[0][0]; for (let i = 0; i { const upArr = arr.splice(0, arr.length / 2); const downArr = arr; const upLeftArr = upArr.map((el) => el.splice(0, el.length..
// 프로그래머스 레벨2 튜플을 풀었습니다. const solution = (s) => { // "{{4,2,3},{3},{2,3,4,1},{2,3}}" const arr = s .split("},") .map((str) => { // [ '4,2,3', '3', '2,3,4,1', '2,3' ] return str .split("") .filter((el) => el !== "{" && el !== "}") .join(""); }) .sort((a, b) => { // [ '3', '2,3', '4,2,3', '2,3,4,1' ] return a.length - b.length; }) .m..
// 프로그래머스 레벨2 땅따먹기를 풀었습니다. // DP인 것은 알았지만, 코드로 구현하는 데에 상당히 오래 걸렸습니다. const solution = (land) => { const DP = new Array(land.length).fill(0); for (let i = 0; i < land.length; i++) { DP[i] = []; } for (let i = 0; i < land[0].length; i++) { DP[0][i] = land[0][i]; } for (let i = 1; i < land.length; i++) { DP[i][0] = land[i][0] + Math.max(DP[i - 1][1], DP[i - 1][2], DP[i - 1][3]); DP[i][1] = land[i][..
// 프로그래머스 레벨2 2개 이하로 다른 비트를 풀었습니다. const ImSoBoring = (num) => { const bits = num.toString(2).split(""); if (num % 2 === 0) { bits.pop(); return parseInt([...bits, "1"].join(""), 2); } else { bits.unshift("0"); for (let i = bits.length - 1; i >= 0; i--) { if (bits[i] === "0") { bits[i] = "1"; bits[i + 1] = "0"; return parseInt(bits.join(""), 2); } } } }; const solution = (numbers) => { return nu..
// 프로그래머스 레벨2 이진 변환 반복하기를 풀었습니다. const solution = (s) => { let zeroCount = 0; let count = 0; while ( (s = s .split("") .filter((el) => { if (el !== "0") { return true; } zeroCount++; return false; }) .join("") .length.toString(2)) !== "1" ) { count++; } return [count + 1, zeroCount]; };