일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- javascript
- 알고리즘
- dp
- type challenge
- BFS
- Nestjs
- TCP
- 크롤링
- dfs
- 쉬운 문제
- Algorithm
- 타입 챌린지
- 레벨 1
- 타입스크립트
- Node.js
- typescript
- 가천대
- 백준
- 문자열
- HTTP
- 수학
- 소켓
- 자바스크립트
- socket
- 그래프
- 프로그래머스
- ip
- 프로그래머스 레벨 2
- Crawling
- HTTP 완벽 가이드
- Today
- Total
목록프로그래밍/알고리즘 풀이 (210)
kakasoo
function* combinations(elements, selectNumber) { for (let i = 0; i < elements.length; i++) { if (selectNumber === 1) { yield [elements[i]]; } else { const fixed = elements[i]; const rest = elements.slice(i + 1); for (const a of combinations(rest, selectNumber - 1)) { yield [fixed, ...a]; } } } } function solution(number) { const answer = []; /** * number 중 3개의 요소를 조합한 후, 그 조합의 합이 0이 되는 케이스를 찾는다...
/** * 프로그래머스 연속 부분 수열 합의 개수 * * 푼 날짜 : 2023.06.04 * * @param {number[]} elements * @returns {number} */ function solution(elements) { /** * 원형으로 쓰인 수열이기 때문에 반복을 표현한다. * 이렇게 하지 않을 경우, `array.prototype.at()`을 이용하는 방법도 있다. */ elements.push(...elements); /** * answer에 시작 지점으로부터 n개를 담았을 때의 부분 수열 합을 모두 담는다. * 반복되었기 때문에 2번 씩 담기는 것을 막고자 length와 start는 모두 전체 길이의 반까지만을 허용한다. */ const answer = []; for (let..
/** * 프로그래머스 귤 고르기 * * 푼 날짜 : 2023.06.04 */ function solution(k, tangerine) { /** * 배열을 이용해서 풀 경우 length가 클 경우 시간 초과가 발생한다. * 따라서 `arr.filter`를 이용하지 않아도 되게끔 객체에 매핑한다. * * { '1': 2, '2': 2 ... }의 형태가 된다. */ const sizeMap = {}; tangerine.map((el) => { sizeMap[el] = sizeMap[el] ? sizeMap[el] + 1 : 1; }); /** * 전체 수에 의해 정렬되게끔 한다. */ const sorted = Object.entries(sizeMap).sort((a, b) ..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let number; rl.on("line", (line) => { if (!number) { number = Number(line); } else { const revsered = line .split(" ") .map((word) => word.split("").reverse().join("")) .join(" "); console.log(revsered); } }); 각 문장을, 띄어쓰기 단위로 자른다. 단어가 된다. 단어를 글자 단위로 자른다. 글자를 뒤집어서 다시 합친다. ..
// 프로그래머스 레벨 1 숫자 문자열과 영단어를 풀었습니다. const numbers = [ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", ]; const solution = (s) => { const str = s.split(""); let stack = []; let answer = ""; for (const a of str) { if (isNaN(Number(a))) { stack.push(a); const num = numbers.findIndex((el) => el === stack.join("")); if (num !== -1) { answer += String(num); stack = []; }..
// 백준 11723번 node.js는 메모리 제한으로 풀 수 없는 문제. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const input = []; 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 = elements.slice..
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", () => { const map = input.map((row) => row.split(" ")); const nullPoint = []; for (let i = 0; i < map.length; i++) { for (let j = 0; j < map[i].length; j++) { if (map[i][j] == 0) { nullPoint.push..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { const num = Number(line); const rows = new Array(num + 1).fill(0).map((el) => 0); const isAble = (row) => { for (let i = 1; i < row; i++) { if ( rows[i] === rows[row] || Math.abs(rows[row] - rows[i]) === row - i ) { return false; } } return true;..
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", () => { const num = Number(input.splice(0, 1)) + 1; const expression = input[0].split(" "); const numbers = new Array(10).fill(0).map((el, i) => i); const visited = new Array(10).fill(false); con..
// 백준 1182번 부분 수열의 합을 풀었습니다. 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 = elements.slice(i + 1); for (const a of combin..
// 백준 14889번 스타트와 링크를 풀었습니다. // 조합을 사용하여 풀었습니다. 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 = elements.slice(i + 1); for..
// 백준 14888번 연산자 끼워넣기를 풀었습니다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); 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; i++) { const start = a.slice(0, i)..