Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kirsch x patch 1 #17

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions HyeonWook/DFS&BFS/banUsers
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function solution (user_id, banned_id) {

let banLists = [];

//배열을 DSF 탐색
function DSF(users, bIds, bans){
if(bIds.length === 0) {
banLists.push(bans)

return;
}

for(let i =0; i<users.length; i++){
if(match(users[i], bIds[0])){
DSF([...users.slice(0,i), ...users.slice(i+1)], bIds.slice(1), [...bans, users[i]])
}
}
}

DSF(user_id, banned_id, [])

// 중복 제거
banLists = banLists.map(list => JSON.stringify(list.sort()))

return Array.from(new Set(...[banLists])).length

// for문으로 문자열 일치 판별
function match(idA, idB){
if(idA.length !== idB.length) return false;
for(let i =0; i<idA.length; i++){
if(idB[i] === "*") continue;
if(idA[i] !== idB[i]) return false;
}
return true;
}


}