알고리즘
-
[제주코딩베이스캠프] Javascript 알고리즘 100일 챌린지 11 ~ 17일차알고리즘 2024. 4. 22. 09:49
🔥 몰랐던 내용 [12일차] 📦 Array.reverse() 기존에 생각한 방법은 Array로 만드는 과정까지는 동일하다. 하지만 나는 pop()을 통해서 나온 값으로 새로운 배열을 만들어서 return 하려하였는데 이러한 방법을 쓰지않고 그냥 reverse()를 사용하면 자연스럽게 뒤집을 수 있다 영상에서는 Array(words)이런식으로 문자열로 만드는데 split()을 사용하는 방법도 있다고 말한다. [14일차] 📦 s1과 s2의 유사도를 구하자 유사도를 구하는 문제에서 Array.filter()와 Array.includes()를 통해서 쉽게 구할 수가 있구나!!! function solution(s1, s2) { return s1.filter(v => s2.includes(v)).length } ..
-
[제주코딩베이스캠프] Javascript 알고리즘 100일 챌린지 1 ~ 10일차알고리즘 2024. 4. 18. 23:04
🔥 몰랐던 내용 [1일차] 📦 ~~(10 / 5) 몫을 구하는 과정에서 사용되는 방식으로 실수로 출력되지 않고 정수로 출력하기 위해서 사용함 ~는 부정 연산자로써 bit가 1001인 수 5를 0110으로 뒤집는 역할을 해서 결과적으로 -(n + 1)의 값을 출력하는데 이러한 부정 연산자를 2번 사용함으로써 원래 값으로 돌리면 정수로 출력이 된다. Math.floor(10 / 5)와 동일한 역할을 한다. [5일차] 📦 Array.reduce() reduce()의 경우에는 초기값을 설정하지 않았을 때 문제점이 생긴다 그렇기 때문에 2번째 인자로 전달되는 초기값(이 문제에서는 0)을 설정하므로써 빈 값(짝수의 합을 구하는 과정 중 n = 1일 경우에는 빈 배열이 생성된다)에 대한 문제를 해결하기 위해 초기값을..
-
[BOJ - Silver 5] 11866 요세푸스 문제 0알고리즘 2024. 4. 3. 09:28
❓문제 설명 구현문제 순열을 구하는 문제로 N명이 원을 이루고 있을 때 K번째 순서를 계속해서 제거해 나가는 방식이다. 최종적으로 를 구하면 된다 ✅ 문제 해결 배열에서 특정 K의 배수에 해당하는 인원을 제거하고 그 이후로 다시 K를 세면서 계속 제거를 하는 방식이 필요했다. 처음에 계속 문제를 풀려고 했는데 제대로 구현이 안되서 참고를 하여 구현을 하게 되었다. const fs = require("fs"); const [n, k] = fs .readFileSync("/dev/stdin") .toString() .trim() .split(" ") .map(Number); const solution = (n, k) => { const people = Array.from({ length: n }, (_, i..
-
[프그래머스 2단계] 두 원 사이의 정수 쌍알고리즘 2024. 3. 23. 20:52
❓문제 설명 두 개의 반지름을 받을 것임 이것을 통해서 만들어진 2개의 원이 있는데 이 원들이 가지는 정수 좌표값 중 공통된 것을 빼고 나머지를 구하는 것임 ✅ 문제 해결 원의 반지름을 통해서 정수좌표를 어떻게 구할 수 있을지 알아보았으며 x2 + y2 = r2이 공식을 통해서 구할 수 있는 방법을 알아보았음 큰 원의 정수좌표를 객체로 만들고 작은 원의 정수좌표를 구할 때 공통된 것이 있다면 객체에서 없애보자. function solution(r1, r2) { var answer = 0; for(var x = 1;xx){ var minY = Math.ceil(Math.sqrt(r1**2 - x**2)); } else{ var minY = 0; } answer+= (maxY - minY + 1); } re..