์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- next13 emotion
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- suspense ๋ณ๋ชฉํ์
- ์ค์ฝํ
- js ๋ฌธ์์ด ์์ถ
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- suspense ๋์์๋ฆฌ
- suspense ๋น๋๊ธฐ
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- suspense react-query
- ๊ตฌ๋ฆํค
- js ์ค์ฝํ
- ๋ฐฑ์ค 2108 nodejs
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- emtion app router
- ์ต์ ๋์ฒด์ด๋
- ์นด์นด์ค ์ฝํ
- ๋ฐฑ์ค 1339๋ฒ js
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- emotion RSC
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- app router emotion
- js
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ์ฌ์ฉ์ฑ ๊ฐ์
- ๋ฐฑ์ค 1339๋ฒ nodejs
- Today
- Total
Lennon FE
[ํ๋ก๊ทธ๋๋จธ์ค Lv.3] ๋ถ๋ ์ฌ์ฉ์ (js) ๋ณธ๋ฌธ
https://programmers.co.kr/learn/courses/30/lessons/64064
์ฝ๋ฉํ ์คํธ ์ฐ์ต - ๋ถ๋ ์ฌ์ฉ์
๊ฐ๋ฐํ ๋ด์์ ์ด๋ฒคํธ ๊ฐ๋ฐ์ ๋ด๋นํ๊ณ ์๋ "๋ฌด์ง"๋ ์ต๊ทผ ์งํ๋ ์นด์นด์ค์ด๋ชจํฐ์ฝ ์ด๋ฒคํธ์ ๋น์ ์์ ์ธ ๋ฐฉ๋ฒ์ผ๋ก ๋น์ฒจ์ ์๋ํ ์๋ชจ์๋ค์ ๋ฐ๊ฒฌํ์์ต๋๋ค. ์ด๋ฐ ์๋ชจ์๋ค์ ๋ฐ๋ก ๋ชจ์ ๋ถ๋
programmers.co.kr
function solution(user_id, banned_id) {
const permutationUser = permutation(user_id, banned_id.length);
const value = permutationUser.filter(v => check_id(v, banned_id))
const answer = [...new Set(value.map(v=> v.sort().join(' ')))];
return answer.length;
}
function check_id(u_id, b_id) {
u_id = u_id.sort((a,b) => a.length - b.length);
b_id = b_id.sort((a,b) => a.length - b.length);
for(let i = 0; i < u_id.length; i++) {
if(u_id[i].length !== b_id[i].length) {
return false;
}
for(let j = 0; j < b_id[i].length; j++){
if(u_id[i][j] !== b_id[i][j] && b_id[i][j] !== '*') {
return false;
}
}
}
return true;
}
function permutation(arr, selectNum) {
let result = [];
if (selectNum === 1) return arr.map((v) => [v]);
arr.forEach((v, idx, arr) => {
const fixer = v;
const restArr = arr.filter((_, index) => index !== idx);
const permuationArr = permutation(restArr, selectNum - 1);
const combineFixer = permuationArr.map((v) => [fixer, ...v]);
result.push(...combineFixer);
});
return result;
}
Function permutation
user_id๋ฅผ bannde_id์ ๊ธธ์ด๋งํผ ์์ด์ ๊ตฌํ๋ค.
ex)
user_id = [ '123', '234', '126']
bannde_id = ['1*3', '***']
=> [ ['123', '234'], ['123', '126'], ['234','126'] ]
Function check_id
permutation์์ ์ป์ ๋ฐฐ์ด๊ณผ banned_id๋ฅผ ์ธ์๋ก ๋ฐ๋๋ค.
ex)
['123', '234'], ['1*3', '***'] ๋์ ๊ธธ์ด ์์ ์์ผ๋ก ์ ๋ ฌํ๊ณ , ํด๋น ์กฐ๊ฑด์ ๋ง๋ ์ง ์ฒดํฌํ๋ค.
์กฐ๊ฑด 1
๋ฐฐ์ด ์์์ ๊ธธ์ด๊ฐ ๊ฐ์๊ฐ? '123' ๊ณผ '1*3'์ ๊ธธ์ด๊ฐ ๊ฐ๋ค.
์กฐ๊ฑด 2
๋ ๊ฐ์ด ๊ฐ์๊ฐ? ๊ฐ์ง ์๋ค๋ฉด banned_id์ ๊ฐ์ด '*' ์ธ๊ฐ? 2๊ฐ ๋ค๋ฅด๊ธด ํ์ง๋ง *์ด๋ฏ๋ก ๊ฐ์๊ฑธ๋ก ์ทจ๊ธํ๋ค.
false ํน์ true๋ฅผ return
Function solution
value ๋ณ์์์ filter๋ฅผ ์ด์ฉํด true๋ฅผ ๋ฆฌํดํ๋ ๊ฐ๋ง ๋ชจ์๋ค.
๊ทธ ํ ์ค๋ณต์ ์ ๊ฑฐํ๊ณ , ๊ธธ์ด๋ฅผ returnํด์ฃผ๋ฉด ๋!
'๐ฅ Algorithm > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ค๋ฆฌ๋ฅผ ์ง๋๋ ํธ๋ญ (js) (0) | 2022.02.10 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค Lv.3] ์ด์ค์ฐ์ ์์ํ (js) (0) | 2022.02.03 |
[ํ๋ก๊ทธ๋๋จธ์ค Lv.3] ๋จ์ ์นด๋ฉ๋ผ (js) (0) | 2022.01.30 |
[ํ๋ก๊ทธ๋๋จธ์ค Lv.2] 2๊ฐ ์ดํ๋ก ๋ค๋ฅธ ๋นํธ (js) (0) | 2022.01.30 |
[ํ๋ก๊ทธ๋๋จธ์ค Lv.1] ํคํจ๋ ๋๋ฅด๊ธฐ (js) (0) | 2022.01.24 |