일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- dfs
- 타입 챌린지
- Crawling
- HTTP
- 그래프
- 백준
- socket
- 소켓
- 알고리즘
- dp
- 문자열
- 레벨 1
- 가천대
- TCP
- ip
- 자바스크립트
- 크롤링
- HTTP 완벽 가이드
- javascript
- 수학
- Node.js
- 타입스크립트
- BFS
- 프로그래머스
- Algorithm
- 프로그래머스 레벨 2
- 쉬운 문제
- Nestjs
- typescript
- type challenge
- Today
- Total
목록프로그래밍/알고리즘 풀이 (210)
kakasoo
// 프로그래머스 레벨1 행렬의 덧셈을 풀었습니다. function solution(arr1, arr2) { return arr1.map((el, i) => el.map((n, j) => (n += arr2[i][j]))); } 다 더해주기만 하면 되는 간단한 문제.
// 프로그래머스 레벨1 핸드폰 번호 가리기를 풀었습니다. function solution(phone_number) { let a, b, c, d, e; let arr = ([a, b, c, d, ...e] = phone_number.split("").reverse()); return [e.map((el) => "*").join(""), d, c, b, a].join(""); } 구조분해할당과 나머지 연산자를 이용하면 쉽게 가능해진다.
// 프로그래머스 레벨1 하샤드 수를 풀었습니다. function solution(x) { return ( x % String(x) .split("") .map((el) => Number(el)) .reduce((acc, cur) => acc + cur) === 0 ); } 자기 자신의 각 자릿수의 합으로 나누어 떨어지는 수.
// 프로그래머스 레벨1 평균구하기를 풀었습니다. function solution(arr) { return arr.reduce((acc, cur) => acc + cur) / arr.length; }
// 프로그래머스 레벨1 최대공약수와 최소공배수를 풀었습니다. function solution(n, m) { if (n > m) [n, m] = [m, n]; const arr = []; for (let i = 2; i acc * cur); const max = min === 1 ? n * m : min * n * m; return [min, max]; } 이제는 gcd를 구하지, 저렇게 구하지 않는다. 재귀적 방법이 더 쉽기 때문이다.
// 프로그래머스 레벨1 짝수와 홀수를 풀었습니다. function solution(num) { if (num % 2 === 0) return "Even"; return "Odd"; } const solution = (num) => ["Even", "Odd"][num]; 이렇게도 가능하긴 하다. 작년 9월에 풀어서 코드가 C++ 같다.
// 프로그래머스 level1 제일 작은 수 제거하기를 풀었습니다. function solution(arr) { let min = 9875654321; if (arr.length === 1) return [-1]; arr.map((el, i) => { if (el < min) min = el; return el; }); arr.splice(arr.indexOf(min), 1); return arr; }
// 프로그래머스 레벨1 정수 내림차순으로 배치하기를 풀었습니다. function solution(n) { return Number(String(n).split("").sort().reverse().join("")); }
// 프로그래머스 레벨1 자연수 뒤집어 배열로 만들기를 풀었습니다. function solution(n) { return String(n) .split("") .map((el) => Number(el)) .reverse(); }
// 프로그래머스 레벨1 이상한 문자 만들기를 풀었습니다. function solution(s) { return s .split(" ") .map((el) => { el = el.split("").map((s, i) => { if (i % 2 === 0) return s.toUpperCase(); return s.toLowerCase(); }); return el; }) .map((el) => el.join("")) .join(" "); }
// 프로그래머스 level1 시저 암호를 풀었습니다. function solution(s, n) { var answer = ""; let big = []; let small = []; for (let i = "A".charCodeAt(0); i big.length - 1) nextPos -= big.length; return big[nextPos]; } else if (small.includes(el)) { let nextPos = small.indexOf(el) + n; if (nextPos > small.length - 1) nextPos -= small.length; return small[nextPos]; } else return el; }); return s.join(""); }