Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
29 | 30 | 31 |
Tags
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- emotion RSC
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- suspense react-query
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- ์นด์นด์ค ์ฝํ
- ๋ฐฑ์ค 1339๋ฒ js
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- ๊ตฌ๋ฆํค
- ์ต์ ๋์ฒด์ด๋
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- ์ค์ฝํ
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- suspense ๋์์๋ฆฌ
- ๋ฐฑ์ค 2108 nodejs
- suspense ๋ณ๋ชฉํ์
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- ๋ฐฑ์ค 1339๋ฒ nodejs
- js ์ค์ฝํ
- next13 emotion
- ์ฌ์ฉ์ฑ ๊ฐ์
- js ๋ฌธ์์ด ์์ถ
- emtion app router
- suspense ๋น๋๊ธฐ
- js
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- app router emotion
Archives
- Today
- Total
Lennon FE
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] ์์ ์ฐพ๊ธฐ (js) ๋ณธ๋ฌธ
728x90
๋ฐ์ํ
https://programmers.co.kr/learn/courses/30/lessons/42839?language=javascript
function solution(numbers) {
const number = [...numbers];
const answer = [];
for(let i = 1; i <= number.length; i++){
permutation(number,i).forEach((v) => {
isPrime(+v) ? answer.push(+v) : answer
});
}
return [...new Set(answer)].length
}
function isPrime(num){
let start = 2;
while (start <= Math.sqrt(num)) {
if (num % start++ < 1){
return false;
}
}
return num > 1;
}
function permutation(arr, selectNum){
const result = [];
if(selectNum === 1) return arr.filter((v)=> [v]);
arr.forEach((v,idx,arr)=>{
const fixer = v;
const restArr = arr.filter((val, index)=> index !== idx);
const permuArr = permutation(restArr, selectNum-1);
const combineFixer = permuArr.map((v)=> fixer + v);
result.push(...combineFixer);
})
return result;
}
permutation ํจ์ => arr => ๋ฐฐ์ด selectNum => ๊ฐ์
selectNum๋งํผ ์กฐํฉํ ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํดํ๋ ํจ์ / ์ค๋ณต๊น์ง ์ ๋ถ ๋ค์ด๊ฐ (011, 11, 0011) ๋์ค์ ์ฒ๋ฆฌ
isPrime ํจ์ => ์์ ์ฒดํฌ ํจ์์ด๋ค. ์ ๊ณฑ๊ทผ์ ํตํด ์๊ฐ๋ณต์ก๋๋ฅผ ์ค์ผ ์ ์๋ค.
solution์์ ์กฐํฉํ ๊ฒฐ๊ณผ๋ฅผ answer์ ์ ๋ถ ๋ด๊ณ ์ค๋ณต์ ์ ๊ฑฐํ๊ธฐ ์ํด Set์ ์ฌ์ฉํ ํ answer์ ๊ธธ์ด๋ฅผ ๋ฆฌํดํ๋ฉด ๋!
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] n์ง์ ๊ฒ์(js) (0) | 2022.01.22 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] ํํ (js) (0) | 2021.11.18 |
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] ํ๋ฆฐํฐ (js) (0) | 2021.11.10 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ฐฉ๋ฌธ ๊ธธ์ด (js) (0) | 2021.11.08 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์คํฌํธ๋ฆฌ (js) (0) | 2021.11.07 |
Comments