-
Notifications
You must be signed in to change notification settings - Fork 2
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
56-xxubin04 #211
56-xxubin04 #211
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.
listλ‘ λ°μ΄ν°λ₯Ό μ μ₯νλ©΄, μμ μ€λ³΅ κ²μ¬ λ±λ±μ λ‘μ§μ μ²λ¦¬νλ λ° μκ°μ΄ μ€λκ±Έλ¦¬μ£ . set
μ μ¬μ©νλ©΄
m1 = Counter([str1[i:i+2].lower() for i in range(len(str1) - 1) if str1[i:i+2].isalpha()])
m2 = Counter([str2[i:i+2].lower() for i in range(len(str2) - 1) if str2[i:i+2].isalpha()])
Counter
λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©νλ©΄ μλμΌλ‘ κ°μ μΉ΄μ΄ν
κ²°κ³Όλ₯Ό λμ
λ리 ννλ‘ λ°νν΄μ€λλ€.
intersection = sum((m1 & m2).values())
union = sum((m1 | m2).values())
νμ΄μ¬μμλ &
μ°μ°μμ |
μ°μ°μλ₯Ό μ΄μ©ν΄ κ΅μ§ν©κ³Ό ν©μ§ν©μ ꡬν μ μμ΅λλ€.
if union == 0:
return 65536
ν©μ§ν©μ΄ 0μ΄λΌλ 건 λ μ§ν© κ° κ³΅ν΅ μμκ° μλ€λ λ»μ΄λ, 1μ μλ―Ένλ 65536μ λ°νν©λλ€.
similarity = intersection / union
return int(similarity * 65536)
μλλΌλ©΄ μ μ¬λλ₯Ό κ³μ°ν΄ 65536μ κ³±νκ³ μμμ μ λ²λ¦° κ°μ λ°ννλ©΄ λμ£ .
μ 체 μ½λ
from collections import Counter
def solution(str1, str2):
m1 = Counter([str1[i:i+2].lower() for i in range(len(str1) - 1) if str1[i:i+2].isalpha()])
m2 = Counter([str2[i:i+2].lower() for i in range(len(str2) - 1) if str2[i:i+2].isalpha()])
intersection = sum((m1 & m2).values())
union = sum((m1 | m2).values())
if union == 0:
return 65536
similarity = intersection / union
return int(similarity * 65536)
μ΄ λ¬Έμ μ²μ λ΄€μ λ μ€λͺ μ μ λλ‘ μ΄ν΄ λͺ»νλ κΈ°μ΅μ΄ μλ€μ γ γ
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.
pythonμΌλ‘ νκΈ΄νλλ°, 미리 μ€κ³μνκ³
νΈλ λ°λ‘ μ½λ μμ±ν΄λ³΄λ μ‘°κΈ λλ½λ€μ,..γ
νμ΄μ¬μμ κ΅μ§ν© ν©μ§ν©μ setμ μ΄μ©ν΄μ μλμ κ°μ΄ μ¬μ© κ°λ₯ν©λλ€ !
from math import floor
def solution(str1, str2):
answer = 0
str1, str2 = str1.lower(), str2.lower()
str1_list, str2_list = []. []
for i in range(len(str1) - 1):
if str1[i].isalpha() and str1[i+1].isalpha():
str1_list.append(str1[i:i + 2])
for i in range(len(str2) - 1):
if str2[i].isalpha() and str2[i + 1].isalpha():
str2_list.append(str2[i:i + 2])
intersection_list = set(str1_list) & set(str2_list)
union_list = set(str1_list) | set(str2_list)
if len(union_list) == 0:
return 65536
intersection_len = sum([min(str1_list.count(intersection), str2_list.count(intersection)) for intersection in intersection_list])
union_len = sum([max(str1_list.count(union), str2_list.count(union)) for union in union_list])
answer = floor((intersection_len / union_len) * 65536)
return answer
π λ¬Έμ λ§ν¬
νλ‘κ·Έλλ¨Έμ€ - λ΄μ€ ν΄λ¬μ€ν°λ§
βοΈ μμλ μκ°
20λΆ
β¨ μλ μ½λ
1. λ¬Έμ μ΄ν΄
μμΉ΄λ μ μ¬λ
J(A, B)
* 65536μμ μμμ μλ μλ λ²λ¦¬κ³ μΆλ ₯νλ λ¬Έμ μ΄λ€.쑰건
λ¬Έμμ΄ str1, str2λ₯Ό μΈμ νλ λ λ¬Έμμ© μλΌμ μ§ν©μ ꡬμ±νλ€.
aa1+aa2
,AAAA12
μ§ν© Aμ μ§ν© Bκ° λͺ¨λ 곡μ§ν©μΈ κ²½μ°μλ λλμ μ΄ μ μλμ§ μμΌλ―λ‘ J(A,B) = 1λ‘ μ μνλ€.
μμΉ΄λ μ μ¬λ J(A, B) = λ μ§ν©μ κ΅μ§ν© ν¬κΈ° / λ μ§ν©μ ν©μ§ν© ν¬κΈ°
2. μ½λ λΆμ
λ¬Έμμ΄μ λ κΈμμ© μλΌμ μνλ²³μΌλ‘λ§ κ΅¬μ±λ κ²½μ°μλ§ κ°κ°μ μ§ν©μ μΆκ°ν΄μ€λ€.
λ μ§ν©μ ν¬κΈ°μ ν©μΈ
total
κ³Ό λ μ§ν©μ κ΅μ§ν©μ ν¬κΈ°μΈduplication
μ μ μνλ€.μ§ν© A(
list1
)μ κ° μμκ° μ§ν© B(list2
)μ μλ€λ©΄, μ§ν© Bμ ν΄λΉ μμλ₯Ό μ§μμ£Όκ³ duplicationμ 1μ μΆκ°ν΄μ€λ€. μ΄λ, μ§ν© Bμ ν΄λΉ μμλ₯Ό μ§μμ£Όλ μ΄μ λ κ΅μ§ν©μ μ΄λ―Έ μΆκ°λ μμλ‘ μκ°νμ¬μΌ νκΈ° λλ¬Έμ΄λ€. μ’ λ μμΈνκ² λ§νμλ©΄, ["AA", "AA", "BB"], ["AA"]μ κ΅μ§ν©μ ["AA"]μ΄μ§, ["AA", "AA"]κ° μλλΌλ κ²μ΄λ€. κ·Έλ¬λ―λ‘ λμΌν μμκ° λνλλ€λ©΄, λ μ§ν© μ€ νλμ μ§ν©μμ ν΄λΉ μμλ₯Ό μ§μμΌ νλ€.μ΄λ, μμμ μΈκΈν μ£Όμν΄μΌ ν μ μ μκΈ°νμ¬μΌ νλ€.
μ΄λ λ¬Έμ λ₯Ό κ°λ³κ² λ³΄κ³ μ§λκ°λλ ν μ€νΈμΌμ΄μ€ 5μμ νλ Έλ€κ³ λ΄λ€. μκ³ λ΄€λλ 쑰건문μ λ€μκ³Ό κ°μ΄ μμ±νμκΈ° λλ¬Έμ΄μλ€.
μ΄λΌ? λκ° λ¬Έμ νλ κ·Έλ₯
len(list1) == 0
μ μ§μ λλ ν΅κ³Όν΄μ κ·Έλ₯ κ·Έλ ꡬλνκ³ μ§λκ°λλ°, μ§κΈ μκ°ν΄λ³΄λ μ΄μ’κ² ν μ€νΈμΌμ΄μ€λ₯Ό ν΅κ³Όν κ² κ°λ€μ?λ μ§ν© λͺ¨λ 곡μ§ν©μΈ κ²½μ°μ΄κ±°λ ν©μ§ν©κ³Ό κ΅μ§ν©μ ν¬κΈ°κ° κ°μ J(A, B)κ° 1μ΄ λλ κ²½μ°μλ§ 65536μ λ°νν΄μΌ ν©λλ€. κ·Έλμ μ€μ 쑰건μ λ€μκ³Ό κ°μ΄ λκ² λ€μ.
μ΄ λΆλΆλ§ μμ ν΄μ λ€μ μ μΆν΄λ³΄λ μ ν΅κ³Όλλ€μ~
3. μ 체 μ½λ
π μλ‘κ² μκ²λ λ΄μ©
μ λ²μ κ΅ν©μ λ°° νΈμ μΉ΄μΉ΄μ€ λ¬Έμ λ μ΄λ° κ²½μ°κ° μμλ κ² κ°μλ°, μκ°λ³΄λ€ κ·Έλ° κ²½μ°κ° λ§κ΅°μ..?!
μ λ²μ£Όμ μκ³ λ¦¬μ¦ λͺ» μ¬λ €μ μ£μ‘ν©λλ€.... λ€μ μ΄μ¬ν ν κ²μ..!ππ»