-
Notifications
You must be signed in to change notification settings - Fork 1
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
14-SeongHoonC #50
14-SeongHoonC #50
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ¨μ μ‘°ν© λ¬Έμ λ‘ μλͺ» λ΄€λ€κ° μκ° λ§μ΄ λ¨Ήμλ€μ.. μ¬λ°λ λ¬Έμ μμ΄λ€
answer =0
list_for_cases = []
def solution(user_id, banned_id):
matching_banned_id = {banned : set() for banned in banned_id}
for banned in banned_id :
for user in user_id :
if len(user) == len(banned) :
count_char = 0
for idx in range(0, len(banned)) :
if user[idx] != banned[idx] and banned[idx]!='*' :
break
count_char += 1
if count_char == len(banned) :
matching_banned_id[banned].add(user)
# print(matching_banned_id)
dfs(matching_banned_id, banned_id,0,[])
# print(list_for_cases)
return answer
def dfs(match, banned_id, idx, list_for_case) :
global answer
global list_for_cases
if idx == len(banned_id) :
if len(list_for_cases) == 0 or not set(list_for_case) in list_for_cases :
list_for_cases.append(set(list_for_case))
answer+=1
return
for banned in match[banned_id[idx]] :
# print(banned)
if not banned in list_for_case:
list_for_case.append(banned)
dfs(match, banned_id, idx+1, list_for_case)
list_for_case.pop()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved μλͺ» μ¬λ¦Ό!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμ€λκ»μ μ‘°ν©μΌλ‘ λΉλ²Όλ³΄μ
¨λ€κΈΈλ μ λ λΉλ²Όλ΄€μ΅λλ€.
λΉκ²νκ² νμ΄μ¬μ λ΄μ₯ν¨μ λ κ°λ₯Ό μΌμ΅λλ€λ§..
from itertools import permutations
import re
def find(ids, patterns):
for i in range(len(ids)):
# λ¬Έμμ ν¨ν΄μ΄ μΌμΉνλ€λ©΄?
if re.match(patterns[i], ids[i]) and len(ids[i]) == len(patterns[i]):
continue
else:
return False
return True
def solution(user_id, banned_id):
answer = []
# permutations(iter, length) νλ©΄ iterμμμ lengthκΈΈμ΄λ§νΌμ
# μμ΄μ λͺ¨λ λ½μμ€λλ€.
id_permutation = list(permutations(user_id, len(banned_id)))
# μ κ·ννμ μ¨λ¨ΉκΈ°μν΄μ *μ .μΌλ‘ λ°κΏμ€λλ€. (λͺ¨λ λ¬Έμ)
for i in range(len(banned_id)):
banned_id[i] = banned_id[i].replace('*', '.')
for perm in id_permutation:
if find(perm, banned_id):
# μ€λ³΅μ΄ μλμ§ κ²μ¬νκΈ° μν΄μ μ§ν©μλ£νμΌλ‘ λΉκ΅ν΄μ€λλ€.
if not set(perm) in answer:
answer.append(set(perm))
return len(answer)
π λ¬Έμ λ§ν¬
λΆλ μ¬μ©μ
βοΈ μμλ μκ°
1μκ° 20λΆ
β¨ μλ μ½λ
dfs λ μ§μ§μ§μ§ μ€λλ§μ νΈλ€μ..
π μλ‘κ² μκ²λ λ΄μ©
dfs ν λ λ μ΄μ κ°λ₯μ±μ΄ μλ λΆλΆμ νμνμ§ μλ κ²μ κ°μ§μΉκΈ°λΌκ³ νλ€.
μκ°μ΄κ³Όλ₯Ό λ©΄ν μ μλ€.