๋‚ด ์ธ์ƒ์—์„œ ๋ฏฟ์„ ๊ฑด ์˜ค์ง ๋‚˜ ์ž์‹ ๋ฟ!

The only one you can truly trust is yourself.

๊ฒŒ์ž„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ/Python ํ”„๋กœ๊ทธ๋ž˜๋ฐ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค [1์ฐจ] ๋‰ด์Šคํด๋Ÿฌ์Šคํ„ฐ๋ง

๐ŸŽฎinspirer9 2023. 2. 21. 11:23
728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ ์„ค๋ช…

์—ฌ๋Ÿฌ ์–ธ๋ก ์‚ฌ์—์„œ ์Ÿ์•„์ง€๋Š” ๋‰ด์Šค, ํŠนํžˆ ์†๋ณด์„ฑ ๋‰ด์Šค๋ฅผ ๋ณด๋ฉด ๋น„์Šท๋น„์Šทํ•œ ์ œ๋ชฉ์˜ ๊ธฐ์‚ฌ๊ฐ€ ๋งŽ์•„ ์ •์ž‘ ํ•„์š”ํ•œ ๊ธฐ์‚ฌ๋ฅผ ์ฐพ๊ธฐ๊ฐ€ ์–ด๋ ต๋‹ค. Daum ๋‰ด์Šค์˜ ๊ฐœ๋ฐœ ์—…๋ฌด๋ฅผ ๋งก๊ฒŒ ๋œ ์‹ ์ž…์‚ฌ์› ํŠœ๋ธŒ๋Š” ์‚ฌ์šฉ์ž๋“ค์ด ํŽธ๋ฆฌํ•˜๊ฒŒ ๋‹ค์–‘ํ•œ ๋‰ด์Šค๋ฅผ ์ฐพ์•„๋ณผ ์ˆ˜ ์žˆ๋„๋ก ๋ฌธ์ œ์ ์„ ๊ฐœ์„ ํ•˜๋Š” ์—…๋ฌด๋ฅผ ๋งก๊ฒŒ ๋˜์—ˆ๋‹ค.

๊ฐœ๋ฐœ์˜ ๋ฐฉํ–ฅ์„ ์žก๊ธฐ ์œ„ํ•ด ํŠœ๋ธŒ๋Š” ์šฐ์„  ์ตœ๊ทผ ํ™”์ œ๊ฐ€ ๋˜๊ณ  ์žˆ๋Š” "์นด์นด์˜ค ์‹ ์ž… ๊ฐœ๋ฐœ์ž ๊ณต์ฑ„" ๊ด€๋ จ ๊ธฐ์‚ฌ๋ฅผ ๊ฒ€์ƒ‰ํ•ด๋ณด์•˜๋‹ค.

  • ์นด์นด์˜ค ์ฒซ ๊ณต์ฑ„..'๋ธ”๋ผ์ธ๋“œ' ๋ฐฉ์‹ ์ฑ„์šฉ
  • ์นด์นด์˜ค, ํ•ฉ๋ณ‘ ํ›„ ์ฒซ ๊ณต์ฑ„.. ๋ธ”๋ผ์ธ๋“œ ์ „ํ˜•์œผ๋กœ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ
  • ์นด์นด์˜ค, ๋ธ”๋ผ์ธ๋“œ ์ „ํ˜•์œผ๋กœ ์‹ ์ž… ๊ฐœ๋ฐœ์ž ๊ณต์ฑ„
  • ์นด์นด์˜ค ๊ณต์ฑ„, ์‹ ์ž… ๊ฐœ๋ฐœ์ž ์ฝ”๋”ฉ ๋Šฅ๋ ฅ๋งŒ ๋ณธ๋‹ค
  • ์นด์นด์˜ค, ์‹ ์ž… ๊ณต์ฑ„.. "์ฝ”๋”ฉ ์‹ค๋ ฅ๋งŒ ๋ณธ๋‹ค"
  • ์นด์นด์˜ค "์ฝ”๋”ฉ ๋Šฅ๋ ฅ๋งŒ์œผ๋กœ 2018 ์‹ ์ž… ๊ฐœ๋ฐœ์ž ๋ฝ‘๋Š”๋‹ค"

๊ธฐ์‚ฌ์˜ ์ œ๋ชฉ์„ ๊ธฐ์ค€์œผ๋กœ "๋ธ”๋ผ์ธ๋“œ ์ „ํ˜•"์— ์ฃผ๋ชฉํ•˜๋Š” ๊ธฐ์‚ฌ์™€ "์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ"์— ์ฃผ๋ชฉํ•˜๋Š” ๊ธฐ์‚ฌ๋กœ ๋‚˜๋‰˜๋Š” ๊ฑธ ๋ฐœ๊ฒฌํ–ˆ๋‹ค. ํŠœ๋ธŒ๋Š” ์ด๋“ค์„ ๊ฐ๊ฐ ๋ฌถ์–ด์„œ ๋ณด์—ฌ์ฃผ๋ฉด ์นด์นด์˜ค ๊ณต์ฑ„ ๊ด€๋ จ ๊ธฐ์‚ฌ๋ฅผ ์ฐพ์•„๋ณด๋Š” ์‚ฌ์šฉ์ž์—๊ฒŒ ์œ ์šฉํ•  ๋“ฏ์‹ถ์—ˆ๋‹ค.

์œ ์‚ฌํ•œ ๊ธฐ์‚ฌ๋ฅผ ๋ฌถ๋Š” ๊ธฐ์ค€์„ ์ •ํ•˜๊ธฐ ์œ„ํ•ด์„œ ๋…ผ๋ฌธ๊ณผ ์ž๋ฃŒ๋ฅผ ์กฐ์‚ฌํ•˜๋˜ ํŠœ๋ธŒ๋Š” "์ž์นด๋“œ ์œ ์‚ฌ๋„"๋ผ๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ƒˆ๋‹ค.

์ž์นด๋“œ ์œ ์‚ฌ๋„๋Š” ์ง‘ํ•ฉ ๊ฐ„์˜ ์œ ์‚ฌ๋„๋ฅผ ๊ฒ€์‚ฌํ•˜๋Š” ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ• ์ค‘์˜ ํ•˜๋‚˜๋กœ ์•Œ๋ ค์ ธ ์žˆ๋‹ค. ๋‘ ์ง‘ํ•ฉ A, B ์‚ฌ์ด์˜ ์ž์นด๋“œ ์œ ์‚ฌ๋„ J(A, B)๋Š” ๋‘ ์ง‘ํ•ฉ์˜ ๊ต์ง‘ํ•ฉ ํฌ๊ธฐ๋ฅผ ๋‘ ์ง‘ํ•ฉ์˜ ํ•ฉ์ง‘ํ•ฉ ํฌ๊ธฐ๋กœ ๋‚˜๋ˆˆ ๊ฐ’์œผ๋กœ ์ •์˜๋œ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ์ง‘ํ•ฉ A = {1, 2, 3}, ์ง‘ํ•ฉ B = {2, 3, 4}๋ผ๊ณ  ํ•  ๋•Œ, ๊ต์ง‘ํ•ฉ A ∩ B = {2, 3}, ํ•ฉ์ง‘ํ•ฉ A ∪ B = {1, 2, 3, 4}์ด ๋˜๋ฏ€๋กœ, ์ง‘ํ•ฉ A, B ์‚ฌ์ด์˜ ์ž์นด๋“œ ์œ ์‚ฌ๋„ J(A, B) = 2/4 = 0.5๊ฐ€ ๋œ๋‹ค. ์ง‘ํ•ฉ A์™€ ์ง‘ํ•ฉ B๊ฐ€ ๋ชจ๋‘ ๊ณต์ง‘ํ•ฉ์ผ ๊ฒฝ์šฐ์—๋Š” ๋‚˜๋ˆ—์…ˆ์ด ์ •์˜๋˜์ง€ ์•Š์œผ๋‹ˆ ๋”ฐ๋กœ J(A, B) = 1๋กœ ์ •์˜ํ•œ๋‹ค.

์ž์นด๋“œ ์œ ์‚ฌ๋„๋Š” ์›์†Œ์˜ ์ค‘๋ณต์„ ํ—ˆ์šฉํ•˜๋Š” ๋‹ค์ค‘์ง‘ํ•ฉ์— ๋Œ€ํ•ด์„œ ํ™•์žฅํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹ค์ค‘์ง‘ํ•ฉ A๋Š” ์›์†Œ "1"์„ 3๊ฐœ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , ๋‹ค์ค‘์ง‘ํ•ฉ B๋Š” ์›์†Œ "1"์„ 5๊ฐœ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๊ณ  ํ•˜์ž. ์ด ๋‹ค์ค‘์ง‘ํ•ฉ์˜ ๊ต์ง‘ํ•ฉ A ∩ B๋Š” ์›์†Œ "1"์„ min(3, 5)์ธ 3๊ฐœ, ํ•ฉ์ง‘ํ•ฉ A ∪ B๋Š” ์›์†Œ "1"์„ max(3, 5)์ธ 5๊ฐœ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค. ๋‹ค์ค‘์ง‘ํ•ฉ A = {1, 1, 2, 2, 3}, ๋‹ค์ค‘์ง‘ํ•ฉ B = {1, 2, 2, 4, 5}๋ผ๊ณ  ํ•˜๋ฉด, ๊ต์ง‘ํ•ฉ A ∩ B = {1, 2, 2}, ํ•ฉ์ง‘ํ•ฉ A ∪ B = {1, 1, 2, 2, 3, 4, 5}๊ฐ€ ๋˜๋ฏ€๋กœ, ์ž์นด๋“œ ์œ ์‚ฌ๋„ J(A, B) = 3/7, ์•ฝ 0.42๊ฐ€ ๋œ๋‹ค.

์ด๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฌธ์ž์—ด ์‚ฌ์ด์˜ ์œ ์‚ฌ๋„๋ฅผ ๊ณ„์‚ฐํ•˜๋Š”๋ฐ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ฌธ์ž์—ด "FRANCE"์™€ "FRENCH"๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ด๋ฅผ ๋‘ ๊ธ€์ž์”ฉ ๋Š์–ด์„œ ๋‹ค์ค‘์ง‘ํ•ฉ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ๊ฐ๊ฐ {FR, RA, AN, NC, CE}, {FR, RE, EN, NC, CH}๊ฐ€ ๋˜๋ฉฐ, ๊ต์ง‘ํ•ฉ์€ {FR, NC}, ํ•ฉ์ง‘ํ•ฉ์€ {FR, RA, AN, NC, CE, RE, EN, CH}๊ฐ€ ๋˜๋ฏ€๋กœ, ๋‘ ๋ฌธ์ž์—ด ์‚ฌ์ด์˜ ์ž์นด๋“œ ์œ ์‚ฌ๋„ J("FRANCE", "FRENCH") = 2/8 = 0.25๊ฐ€ ๋œ๋‹ค.

์ œํ•œ ์‚ฌํ•ญ

์ž…๋ ฅํ˜•์‹

  • ์ž…๋ ฅ์œผ๋กœ๋Š” str1๊ณผ str2์˜ ๋‘ ๋ฌธ์ž์—ด์ด ๋“ค์–ด์˜จ๋‹ค. ๊ฐ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋Š” 2 ์ด์ƒ, 1,000 ์ดํ•˜์ด๋‹ค.
  • ์ž…๋ ฅ์œผ๋กœ ๋“ค์–ด์˜จ ๋ฌธ์ž์—ด์€ ๋‘ ๊ธ€์ž์”ฉ ๋Š์–ด์„œ ๋‹ค์ค‘์ง‘ํ•ฉ์˜ ์›์†Œ๋กœ ๋งŒ๋“ ๋‹ค. ์ด๋•Œ ์˜๋ฌธ์ž๋กœ ๋œ ๊ธ€์ž ์Œ๋งŒ ์œ ํšจํ•˜๊ณ , ๊ธฐํƒ€ ๊ณต๋ฐฑ์ด๋‚˜ ์ˆซ์ž, ํŠน์ˆ˜ ๋ฌธ์ž๊ฐ€ ๋“ค์–ด์žˆ๋Š” ๊ฒฝ์šฐ๋Š” ๊ทธ ๊ธ€์ž ์Œ์„ ๋ฒ„๋ฆฐ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด "ab+"๊ฐ€ ์ž…๋ ฅ์œผ๋กœ ๋“ค์–ด์˜ค๋ฉด, "ab"๋งŒ ๋‹ค์ค‘์ง‘ํ•ฉ์˜ ์›์†Œ๋กœ ์‚ผ๊ณ , "b+"๋Š” ๋ฒ„๋ฆฐ๋‹ค.
  • ๋‹ค์ค‘์ง‘ํ•ฉ ์›์†Œ ์‚ฌ์ด๋ฅผ ๋น„๊ตํ•  ๋•Œ, ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž์˜ ์ฐจ์ด๋Š” ๋ฌด์‹œํ•œ๋‹ค. "AB"์™€ "Ab", "ab"๋Š” ๊ฐ™์€ ์›์†Œ๋กœ ์ทจ๊ธ‰ํ•œ๋‹ค.

์ถœ๋ ฅ ํ˜•์‹

  • ์ž…๋ ฅ์œผ๋กœ ๋“ค์–ด์˜จ ๋‘ ๋ฌธ์ž์—ด์˜ ์ž์นด๋“œ ์œ ์‚ฌ๋„๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.
  • ์œ ์‚ฌ๋„ ๊ฐ’์€ 0์—์„œ 1 ์‚ฌ์ด์˜ ์‹ค์ˆ˜์ด๋ฏ€๋กœ,
  • ์ด๋ฅผ ๋‹ค๋ฃจ๊ธฐ ์‰ฝ๋„๋ก 65536์„ ๊ณฑํ•œ ํ›„์— ์†Œ์ˆ˜์  ์•„๋ž˜๋ฅผ ๋ฒ„๋ฆฌ๊ณ  ์ •์ˆ˜๋ถ€๋งŒ ์ถœ๋ ฅํ•œ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ

str1 str2 answer
FRANCE french 16384
handshake shake hands 65536
aa1+aa2 AAAA12 43690
E=M*C^2 e=m*c^2 65536

์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช…

ํ’€์ด

  • ํ•˜! ์ฐธ. ๋‚œ ๋ญ˜๋กœ ๋ณด๊ณ . ์‰ฝ๋„ค.
    • set()์จ์„œ ์ง‘ํ•ฉ ์—ฐ์‚ฐ ํ•˜๋ฉด ๋˜๋Š”๊ฑฐ ์•„๋‹ˆ๋ƒ?
      • ์‘. ์•ˆ๋ผ ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹
def solution(str1, str2):
    answer = 0
    lst1 = list(str1)
    lst2 = list(str2)
    lst3 = []
    lst4 = []
    print(lst1, lst2)
    for i in range(len(lst1)-1):
        _t = lst1[i]+lst1[i+1]
        if _t.isalpha() == True:
            lst3.append(_t)  # _t.lower()๋Š” ๋น„๊ตํ•  ๋•Œ ์จ์•ผํ•œ๋‹ค.
    for i in range(len(lst2)-1):
        _t = lst2[i]+lst2[i+1]
        if _t.isalpha() == True:
            lst4.append(_t)
    print(lst3, lst4)
    set3 = set(lst3)
    set4 = set(lst4)
    print(set3, set4)
    ํ•ฉ์ง‘ํ•ฉ = set3 | set4
    ๊ต์ง‘ํ•ฉ = set3 & set4
    print(ํ•ฉ์ง‘ํ•ฉ, ๊ต์ง‘ํ•ฉ) # ์•„... ์•ˆ๋˜๋„ค?
    return answer
 

[๊ฐœ๋…์ •๋ฆฌ] ํŒŒ์ด์ฌ ๋‹ค์ค‘ ์ง‘ํ•ฉ์˜ ๊ต์ง‘ํ•ฉ, ํ•ฉ์ง‘ํ•ฉ

์ฝ”ํ…Œ ์—ฐ์Šตํ• ๋•Œ๋งˆ๋‹ค ์žŠ์„๋งŒ ํ•˜๋ฉด ๋‚˜์˜ค๋Š” ๋‹ค์ค‘์ง‘ํ•ฉ์ด๋‹ค. ๊ตณ์ด ๋ชฐ๋ผ๋„ ๋˜์ง€๋งŒ, ๋ชจ๋ฅธ์ฑ„ ์“ฐ๋ ค๋ฉด ๋จธ์ง€์†ŒํŠธ๋ฅผ ๊ตฌํ˜„ํ•ด์•ผ ํ•˜๋Š” ๊ต‰์žฅํ•œ ๋ฒˆ๊ฑฐ๋กœ์›€์ด ์žˆ๊ธฐ๋•Œ๋ฌธ์— ์•Œ์•„๋‘๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์„œ ํฌ์ŠคํŒ… ํ•œ๋‹ค. 1.

velog.io

  • ์™€ ์ €๋Ÿฐ ๋ฐฉ๋ฒ•์ด ์žˆ๊ตฌ๋‚˜!
    • ์บ„์‚ฌํ•ฉ๋‹ˆ๋‹ค!
def solution(str1, str2):
    lst1 = list(str1)
    lst2 = list(str2)
    lst3 = []
    lst4 = []
    print(lst1, lst2)
    for i in range(len(lst1)-1):
        _t = lst1[i]+lst1[i+1]
        if _t.isalpha() == True:
            lst3.append(_t.lower())
    for i in range(len(lst2)-1):
        _t = lst2[i]+lst2[i+1]
        if _t.isalpha() == True:
            lst4.append(_t.lower())
    print(lst3, lst4)
    
    lst3_copy = lst3.copy()
    ๊ต์ง‘ํ•ฉ = []
    
    for i in lst4:
        if i in lst3:
            lst3.remove(i)
            ๊ต์ง‘ํ•ฉ.append(i)

    ํ•ฉ์ง‘ํ•ฉ = lst3 + lst4
    
    ma = max(len(ํ•ฉ์ง‘ํ•ฉ), len(๊ต์ง‘ํ•ฉ))
    mi = min(len(ํ•ฉ์ง‘ํ•ฉ), len(๊ต์ง‘ํ•ฉ))
    
    if ma == 0:
        return 65536
    
    J = mi / ma
    
    return int(65536 * J)
    
ํ…Œ์ŠคํŠธ 1
์ž…๋ ฅ๊ฐ’ ใ€‰	"FRANCE", "french"
๊ธฐ๋Œ“๊ฐ’ ใ€‰	16384
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	ํ…Œ์ŠคํŠธ๋ฅผ ํ†ต๊ณผํ•˜์˜€์Šต๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	['F', 'R', 'A', 'N', 'C', 'E'] ['f', 'r', 'e', 'n', 'c', 'h']
['fr', 'ra', 'an', 'nc', 'ce'] ['fr', 're', 'en', 'nc', 'ch']
ํ…Œ์ŠคํŠธ 2
์ž…๋ ฅ๊ฐ’ ใ€‰	"handshake", "shake hands"
๊ธฐ๋Œ“๊ฐ’ ใ€‰	65536
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	ํ…Œ์ŠคํŠธ๋ฅผ ํ†ต๊ณผํ•˜์˜€์Šต๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	['h', 'a', 'n', 'd', 's', 'h', 'a', 'k', 'e'] ['s', 'h', 'a', 'k', 'e', ' ', 'h', 'a', 'n', 'd', 's']
['ha', 'an', 'nd', 'ds', 'sh', 'ha', 'ak', 'ke'] ['sh', 'ha', 'ak', 'ke', 'ha', 'an', 'nd', 'ds']
ํ…Œ์ŠคํŠธ 3
์ž…๋ ฅ๊ฐ’ ใ€‰	"aa1+aa2", "AAAA12"
๊ธฐ๋Œ“๊ฐ’ ใ€‰	43690
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	ํ…Œ์ŠคํŠธ๋ฅผ ํ†ต๊ณผํ•˜์˜€์Šต๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	['a', 'a', '1', '+', 'a', 'a', '2'] ['A', 'A', 'A', 'A', '1', '2']
['aa', 'aa'] ['aa', 'aa', 'aa']
ํ…Œ์ŠคํŠธ 4
์ž…๋ ฅ๊ฐ’ ใ€‰	"E=M*C^2", "e=m*c^2"
๊ธฐ๋Œ“๊ฐ’ ใ€‰	65536
์‹คํ–‰ ๊ฒฐ๊ณผ ใ€‰	ํ…Œ์ŠคํŠธ๋ฅผ ํ†ต๊ณผํ•˜์˜€์Šต๋‹ˆ๋‹ค.
์ถœ๋ ฅ ใ€‰	['E', '=', 'M', '*', 'C', '^', '2'] ['e', '=', 'm', '*', 'c', '^', '2']
[] []
  • ๋‘๊ทผ ๋‘๊ทผ ํ•œ๋‹ค์ž‰... ์ฑ„์  ๊ฐ€์ฆˆ์•„!
def solution(str1, str2):
    lst1 = list(str1)
    lst2 = list(str2)
    lst3 = []
    lst4 = []
    
    for i in range(len(lst1)-1):
        _t = lst1[i]+lst1[i+1]
        if _t.isalpha() == True:
            lst3.append(_t.lower())
    for i in range(len(lst2)-1):
        _t = lst2[i]+lst2[i+1]
        if _t.isalpha() == True:
            lst4.append(_t.lower())
    
    lst3_copy = lst3.copy()
    ๊ต์ง‘ํ•ฉ = []
    
    for i in lst4:
        if i in lst3:
            lst3.remove(i)
            ๊ต์ง‘ํ•ฉ.append(i)

    ํ•ฉ์ง‘ํ•ฉ = lst3 + lst4
    
    ma = max(len(ํ•ฉ์ง‘ํ•ฉ), len(๊ต์ง‘ํ•ฉ))
    mi = min(len(ํ•ฉ์ง‘ํ•ฉ), len(๊ต์ง‘ํ•ฉ))
    
    if ma == 0:
        return 65536
    
    J = mi / ma
    
    return int(65536 * J)
    
์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (0.03ms, 10.3MB)
ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.5MB)
ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.4MB)
ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (0.68ms, 10.5MB)
ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.5MB)
ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.6MB)
ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (0.07ms, 10.5MB)
ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (0.02ms, 10.5MB)
ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (0.06ms, 10.3MB)
ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (0.14ms, 10.5MB)
ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (0.22ms, 10.5MB)
ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (0.01ms, 10.4MB)
ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (0.07ms, 10.5MB)
  • ์ด์ œ๋ณด๋‹ˆ ์ € ํ•ฉ์ง‘ํ•ฉ๊ณผ ๊ต์ง‘ํ•ฉ์„ ๊ตฌํ•˜๋Š” ๋ถ€๋ถ„์ด ํ•ต์‹ฌ์ด๊ตฌ๋‚˜.
    • set์„ ์“ฐ๋ ค๊ณ  ํ•˜๋ฉด ๋ณต์žกํ•ด์ง„๋‹ค.
      • ๊ทธ๋ƒฅ ๊ต์ง‘ํ•ฉ์„ ๋จผ์ € ๊ตฌํ•˜๊ณ , ๊ต์ง‘ํ•จ ๋งŒ๋“ค๋ฉด์„œ ํŒŒ๋จน์€ ๋ฆฌ์ŠคํŠธ3๊ณผ ๋ฆฌ์ŠคํŠธ4๋ฅผ ๋”ํ•˜๋ฉด ํ•ฉ์ง‘ํ•ฉ์ด ๋‚˜์˜ด.
def solution(str1, str2):
    lst1, lst2 = list(str1),list(str2)
    lst3, lst4 = [], []
    
    for i in range(len(lst1)-1):
        _t = lst1[i]+lst1[i+1]
        if _t.isalpha() == True:
            lst3.append(_t.lower())
            
    for i in range(len(lst2)-1):
        _t = lst2[i]+lst2[i+1]
        if _t.isalpha() == True:
            lst4.append(_t.lower())
    
    ๊ต์ง‘ํ•ฉ = []
    for i in lst4:
        if i in lst3:
            lst3.remove(i)
            ๊ต์ง‘ํ•ฉ.append(i)
    ํ•ฉ์ง‘ํ•ฉ = lst3 + lst4
    
    ma = max(len(ํ•ฉ์ง‘ํ•ฉ), len(๊ต์ง‘ํ•ฉ))
    mi = min(len(ํ•ฉ์ง‘ํ•ฉ), len(๊ต์ง‘ํ•ฉ))
    
    if ma == 0:
        return 65536
    
    return int(65536 * mi / ma)
728x90
๋ฐ˜์‘ํ˜•