ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

[๋ฌธ์ œ]

https://school.programmers.co.kr/learn/courses/30/lessons/17677

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

๋‰ด์Šค ํด๋Ÿฌ์Šคํ„ฐ๋ง

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

 


[ํ’€์ด]

๋ฌธ์ž์—ด 2๊ฐœ์˜ ๋‹ค์ค‘์ง‘ํ•ฉ์— ๋Œ€ํ•œ ์ž์นด๋“œ ์œ ์‚ฌ๋„๋ฅผ ๊ตฌํ•ด์•ผํ•˜๋Š” ๋ฌธ์ œ๋กœ, ์šฐ์„  ์ž์นด๋“œ ์œ ์‚ฌ๋„๋ฅผ ๊ณ„์‚ฐํ•˜๊ธฐ ์•ž์„œ ํ•ฉ์ง‘ํ•ฉ๊ณผ ๊ต์ง‘ํ•ฉ์„ ๊ตฌํ•ดํ– ํ•ฉ๋‹ˆ๋‹ค. 

 

๋ฌธ์ œ์˜ ์˜ˆ์‹œ ์ฒ˜๋Ÿผ A = { 1, 1, 2, 2, 3 } ์™€ B = { 1, 2, 2, 4, 5 }์˜ ๊ต์ง‘ํ•ฉ๊ณผ ํ•ฉ์ง‘ํ•ฉ์„ ๊ตฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

ํ˜„์žฌ A, B๋ฅผ ํƒ์ƒ‰์ค‘์ธ index์˜ ์œ„์น˜๋ฅผ ๊ฐ๊ฐ p1, p2๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ณ  ๋ฌธ์ œ๋ฅผ ํ’€์ดํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

p1๊ณผ p2 ๋ชจ๋‘ 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ ๋์— ๋„๋‹ค๋ฅผ๋•Œ๊นŒ์ง€ ๋น„๊ต์—ฐ์‚ฐ์„ ํ†ตํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ž‘์—…์„ ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค.

  • A[p1] === B[p2]๋ผ๋ฉด ํ•ฉ์ง‘ํ•ฉ, ๊ต์ง‘ํ•ฉ์— AorB์˜ ๊ฐ’์„ ์ถ”๊ฐ€ํ•˜๊ณ  p1๊ณผ p2๋ฅผ ๋ชจ๋‘ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ํ•œ์นธ ์ด๋™
  • A[p1] < B[p2]๋ผ๋ฉด ํ•ฉ์ง‘ํ•ฉ์— A์˜ ๊ฐ’์„ ์ถ”๊ฐ€ํ•˜๊ณ  p1๋ฅผ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ํ•œ์นธ ์ด๋™
  • A[p1] > B[p2]๋ผ๋ฉด ํ•ฉ์ง‘ํ•ฉ์— B์˜ ๊ฐ’์„ ์ถ”๊ฐ€ํ•˜๊ณ  p2๋ฅผ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ํ•œ์นธ ์ด๋™

์ด๋•Œ, ๋งŒ์•ฝ p1์ด๋‚˜ p2์˜ ๊ฐ’์ด ๊ฐ€๋ฅดํ‚ค๋Š” ๋ฐฐ์—ด์˜ ๋งˆ์ง€๋ง‰ index๊นŒ์ง€ ๋น„๊ต์—ฐ์‚ฐ์„ ์™„๋ฃŒํ–ˆ๋‹ค๋ฉด, ์•„์ง ๋์— ๋„๋‹ค๋ฅด์ง€ ๋ชปํ•œ ๋ฐฐ์—ด์˜ ๊ฐ’์„ ๋ชจ๋‘ ํ•ฉ์ง‘ํ•ฉ์— ์ถ”๊ฐ€ํ•˜๊ณ  ์—ฐ์‚ฐ์„ ๋๋ƒ…๋‹ˆ๋‹ค.

 

 

์—ฐ์‚ฐ ๊ณผ์ •์„ ์ž์„ธํžˆ ์‚ดํŽด๋ณด์ž๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

1) p1 = 0, p2 = 0

A[p1]๊ณผ B[p2]์˜ ๊ฐ’์ด ๋‘˜๋‹ค 1์ด๋ฏ€๋กœ ๊ต์ง‘ํ•ฉ, ํ•ฉ์ง‘ํ•ฉ์— ๋ชจ๋‘ ์ถ”๊ฐ€ํ•˜๊ณ  p1++, p2++ ์—ฐ์‚ฐ์„ ํ•ด์ค๋‹ˆ๋‹ค.

2) p2 = 1, p2 = 1

A[p1] < B[p2] -> p1++, ํ•ฉ์ง‘ํ•ฉ์— 1 ๋„ฃ์Œ

3) p1 = 2, p2 = 1

A[p1] === B[p2] -> p1++, p2++, ํ•ฉ์ง‘ํ•ฉ์— 2๋„ฃ๊ณ , ๊ต์ง‘ํ•ฉ 2๋„ฃ์Œ

3) p2 = 3, p3 = 2

A[p1] === B[p2] -> p1++, p2++, ํ•ฉ์ง‘ํ•ฉ์— 2๋„ฃ๊ณ , ๊ต์ง‘ํ•ฉ 2๋„ฃ์Œ

3) p2 = 4, p3 = 3

A[p1] < B[p2] -> p1++, ํ•ฉ์ง‘ํ•ฉ๋„ค 3๋„ฃ์Œ

4) p1์˜ index๊ฐ€ A์˜ length์ธ 5๊ฐ€ ๋˜์–ด ๋ฐ˜๋ณต ์—ฐ์‚ฐ์„ ๋๋‚ด๊ณ  ํ˜„์žฌ 3(p2์ธ ๊ฐ’)  ~ 4(B์˜ lengt-1)๊นŒ์ง€์˜ ๊ฐ’์„ ํ•ฉ์ง‘ํ•ฉ์— ์ถ”๊ฐ€

 

๋”ฐ๋ผ์„œ ํ•ฉ์ง‘ํ•ฉ = {1, 1, 2, 2, 3, 4, 5}, ๊ต์ง‘ํ•ฉ = {1, 2, 2}๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

๋ฌธ์ œ์—์„œ๋Š” ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ๊ธธ์ด 2์˜ ๋ฌธ์ž์Œ์„ ์ด์šฉํ•˜๋ผ๊ณ  ํ•˜์˜€๊ธฐ ๋•Œ๋ฌธ์— ์ง‘ํ•ฉ์„ ๊ตฌํ•ด์ฃผ๋Š” ๊ณผ์ •์—์„œ ์ •๊ทœ์‹์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ•ด์ฃผ์—ˆ๊ณ , ์œ„์˜ ๋ฐฉ์‹๋Œ€๋กœ ํƒ์ƒ‰์„ ์ง„ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด sort ์—ฐ์‚ฐ์„ ํ†ตํ•ด ์ •๋ ฌํ•˜์˜€์Šต๋‹ˆ๋‹ค.


[์ฝ”๋“œ]

function solution(str1, str2) {
    let answer = 0;
    const makeSet = (str) => {
        const strArr = [];
        const regex = /^[a-z|A-Z]+$/;
        for(let i=0;i<str.length-1;i++) {
            const subStr = str.substring(i, i+2).toUpperCase();
            if(regex.test(subStr)) strArr.push(subStr);
        }
        return strArr;
    }
    
    // ์ •๋ ฌ๋œ ์ค‘๋ณต SET์„ ๊ฐ๊ฐ ๋งŒ๋“ฆ
    const str1Set = makeSet(str1).sort();
    const str2Set = makeSet(str2).sort();
    
    let p1 = 0;
    let p2 = 0;
    const union = [];
    const intersection = [];
    while(p1 < str1Set.length && p2 < str2Set.length) {
        // p1, p2 ๊ธฐ์ค€์œผ๋กœ ๋น„๊ตํ•˜๊ณ  ํƒ์ƒ‰์„ ์ง„ํ–‰
        if(str1Set[p1] === str2Set[p2]) {
            union.push(str1Set[p1]);
            intersection.push(str1Set[p1]);
            p1++;
            p2++;
        } else if(str1Set[p1] < str2Set[p2]) {
            union.push(str1Set[p1]);
            p1++;
        } else {
            union.push(str2Set[p2]);
            p2++;
        }
    }
    
    // ์•„์ง str1์ด ๋‹ค ๋“ค์–ด๊ฐ€์ง€ ๋ชปํ–ˆ์œผ๋ฉด ๋‚˜๋จธ์ง€๋ฅผ union์— ์ฑ„์›Œ์คŒ
    if(p1 < str1Set.length) {
        for(let i=p1;i<str1Set.length;i++) {
            union.push(str1Set[i]);
        }
    }
    // ์•„์ง str2์ด ๋‹ค ๋“ค์–ด๊ฐ€์ง€ ๋ชปํ–ˆ์œผ๋ฉด ๋‚˜๋จธ์ง€๋ฅผ union์— ์ฑ„์›Œ์คŒ
    if(p2 < str2Set.length) {
        for(let i=p2;i<str2Set.length;i++) {
            union.push(str2Set[i]);
        }
    }
    
    const uniLen = union.length;
    const interLen = intersection.length;
    if(uniLen === 0 && interLen === 0) {
        answer = 65536; 
    } else {
        answer = Math.floor((interLen/uniLen)*65536);
    }
    
    return answer;
}