일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- BFS
- Nestjs
- dfs
- dp
- Algorithm
- 프로그래머스 레벨 2
- ip
- 가천대
- 소켓
- 자바스크립트
- 문자열
- HTTP 완벽 가이드
- 그래프
- 수학
- socket
- javascript
- TCP
- 크롤링
- 레벨 1
- Node.js
- 프로그래머스
- type challenge
- 타입 챌린지
- HTTP
- typescript
- 타입스크립트
- 쉬운 문제
- 알고리즘
- Today
- Total
목록프로그래밍/알고리즘 풀이 (210)
kakasoo
// 프로그래머스 level1 두 정수 사이의 합을 풀었습니다. function solution(a, b) { if (a < b) { let temp = b; b = a; a = temp; } var answer = (a + b) / 2 * (a - b + 1); return answer; } 등차수열 생각하면 구하기 쉬울 거 같다. 옛날에 풀어서 그런지 코드가 좋지 못하다.
// 프로그래머스 level1 나누어 떨어지는 수 문제를 풀었습니다. function solution(arr, divisor) { var answer = []; arr.map((el, i) => { if (!(el % divisor)) { answer.push(el); } }) if (!answer.length) answer.push(-1); return answer.sort((o1,o2) => o1 - o2); } 딱히 설명할 게 없는 코드다.
// 프로그래머스 level1 같은 수는 싫어 function solution(arr) { let answer = []; arr.map((el, i) => { if (arr[i] !== arr[i-1]) { answer.push(el); } }) return answer; }
// 프로그래머스 level1 가운데 글자 가져오기 function solution(s) { let answer = s.split(''); while(answer.length >= 3) { answer.pop(); answer.shift(); } return answer.join(''); } 가운데 글자를 찾기보다, 그냥 맨앞과 끝에서 한 글자 씩 지워 나가면서 1개 또는 2개 글자가 남을 때까지 반복하게 했다. 그래서 남은 글자를 반환한다.
// 프로그래머스 level1 2016년 문제를 풀었습니다. function getDays(month) { switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 2: return 29; default: return 30; } } function whatDay(answer) { if (answer === 0) return 'FRI'; if (answer === 1) return 'SAT'; if (answer === 2) return 'SUN'; if (answer === 3) return 'MON'; if (answer === 4) retu..
// 프로그래머스 level1 체육복 function solution(n, lost, reserve) { var answer = 0; let array = new Array(n).fill(1); lost.map((losted, i) => {array[losted - 1]--}); reserve.map((rserv, i) => {array[rserv - 1]+= 1}); let count = 0; for (let i = 0; i 0) { count++; } else if (array[i] === 0 && array[i+1] > 1) { count++; array[i+1]--; } else if (array[i] === 0 && array[..
// 프로그래머스 level1 모의고사 const first = [1,2,3,4,5]; const second = [2,1,2,3,2,4,2,5]; const third = [3,3,1,1,2,2,4,4,5,5]; function checkTest (answers, submits) { let count = 0; for (let i = 0; i < answers.length; i++) { if (answers[i] === submits[i % submits.length]) { count++; } } return count; } function solution(answers) { var answer = []; let point = []; point.push(checkTest(answers, first)); ..
// 프로그래머스 level1 k번째 수 const solution = (array, commands) => new Array(commands.length).fill(0).map((el, i) => i + 1).map(el => array.slice(commands[el-1][0] - 1, commands[el-1][1]).sort((o1, o2) => o1 - o2)[commands[el-1][2] -1]); 이 때 내가 왜 이렇게 풀었는지 기억이 나지 않는다. 그냥 함수형 컨셉을 해보고 싶었던 모양이다. 당연히 저런 가독성 없는 코드를 평소에도 짜는 건 아니다. const solution = (array, commands) => { const answer = []; commands.forEach((l..
const checkDoll = (stack, curCount) => { stack.some((el, i) => { if(stack[i] === stack[i+1]) { stack.pop(); stack.pop(); curCount += 2; } }) return curCount; } const solution = (board, moves) => { let answer = 0; let stack = []; moves.map((el) => { board.some((row, height) => { if(row[el -1] != 0) { stack.push(row[el -1]); answer = checkDoll(stack, answer); row[el -1] = 0; return true; } }); });..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { const [E, S, M] = line.split(" ").map(Number); let e = 1; let s = 1; let m = 1; let count = 1; while (true) { if (E === e && S === s && M === m) { console.log(count); return; } e++; s++; m++; count++; if (e > 15) { e = 1; } if (s > 28) { s = 1; }..
귀찮아서 때려 박듯이 풀었다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const people = []; rl.on("line", (line) => { people.push(line); if (people.length === 9) { main(people); } }); /** * * @param {string[]} people */ const main = (people) => { const heights = people.map(Number).sort((a, b) => a - b); const sum = heights.red..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { let [a, b, c] = line.split(" ").map(BigInt); const pow = (a, b, c) => { if (b == 0) { return BigInt(1); } const temp = pow(a, BigInt(parseInt(b / BigInt(2))), c); if (b % BigInt(2)) { return (((temp * temp) % c) * a) % c; } else { return (temp * ..