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

문제 019 : 문자열 해싱을 이용한 검색 함수 만들기 #85

Open
wants to merge 2 commits into
base: solutions
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
20 changes: 19 additions & 1 deletion src/tiaz0128/ch_08/solution_019.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
def polynomial_hash(str):
p = 31 # 소수
m = 1_000_000_007 # 버킷 크기
hash_value = 0
for char in str:
hash_value = (hash_value * p + ord(char)) % m
return hash_value


def solution(string_list, query_list):
return
hash_list = [polynomial_hash(str) for str in string_list]

result = []
for query in query_list:
query_hash = polynomial_hash(query)
if query_hash in hash_list:
result.append(True)
else:
result.append(False)
return result
Loading