일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 크롤링
- Crawling
- 소켓
- 쉬운 문제
- dfs
- type challenge
- TCP
- BFS
- 가천대
- HTTP 완벽 가이드
- ip
- 문자열
- Nestjs
- javascript
- 레벨 1
- 프로그래머스 레벨 2
- HTTP
- Node.js
- typescript
- 타입 챌린지
- socket
- 수학
- 프로그래머스
- 자바스크립트
- dp
- Algorithm
- 알고리즘
- 백준
- 타입스크립트
- 그래프
- Today
- Total
목록javascript (104)
kakasoo
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/C7k6U/btraMpP2CB6/CetZ3g6cK3LEnrdWjH91U1/img.png)
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..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/Ywp5N/btq84gApgub/d3io50fI4dThrnhrN1ug10/img.png)
// 프로그래머스 레벨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..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/bgoEo1/btq8Ts2cq9X/4a7uY1P2GCUgjAZUzhwsw1/img.png)
// 프로그래머스 레벨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..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/Exmxa/btq8OisYA7e/LBROOnAqUADtdDCfvlCPi0/img.png)
// 프로그래머스 레벨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진수로 변환하여 구했다.
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/cfQEjG/btq8GPW6WqD/rKalg4AkC0k19dB3vh7Kdk/img.png)
// 프로그래머스 레벨 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..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/blZ0P3/btq8Ga7Q4MX/6R73Pk9TvpllMwEfurO6Z1/img.png)
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..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/bIBG8e/btq8zywci3a/MusS2hm1PXhDUog2rFGk10/img.png)
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] ==..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/y0eR6/btq8xFvj489/y2xaNHObtKsWvwzZauOMy1/img.png)
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..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/1t2Re/btq8ARHMpWk/OPjvY64ad9daWfWnvSdz6k/img.png)
// 프로그래머스 레벨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..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/beq9JZ/btq8xL870yl/e0snZzNiRcE0C6r4DpCvKK/img.png)
// 프로그래머스 레벨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][..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/yqsYJ/btq8w48XoFz/zGQCoQDf8n6kjUaN6V9h0k/img.png)
// 프로그래머스 레벨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..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/er2NBq/btq8wd6jYP6/xogntsgBllZ9s0dOolIddK/img.png)
// 프로그래머스 레벨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]; };