๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿบ ๋งค์ผ ์•Œ๊ณ ๋ฆฌ์ฆ˜

2018 ์นด์นด์˜ค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ 1์ฐจ ๋‰ด์Šค ํด๋Ÿฌ์Šคํ„ฐ๋ง JS ๋ฌธ์ œํ’€์ด

๐Ÿ”—์ง์ ‘ ๋ฌธ์ œ ํ’€๋Ÿฌ๊ฐ€๊ธฐ

 

 

๋ฌธ์ œ

 

๋‘ ๋ฌธ์ž์—ด์„ ์ž์นด๋“œ ์œ ์‚ฌ๋„๋ฅผ ๊ตฌํ•˜๋ผ.

 

  • J(A,B) = ๋‘ ์ง‘ํ•ฉ์˜ ๊ต์ง‘ํ•ฉ ํฌ๊ธฐ๋ฅผ ๋‘ ์ง‘ํ•ฉ์˜ ํ•ฉ์ง‘ํ•ฉ ํฌ๊ธฐ๋กœ ๋‚˜๋ˆˆ ๊ฐ’.
  • ๋‘ ์ง‘ํ•ฉ์ด ๊ณต์ง‘ํ•ฉ์ผ ๊ฒฝ์šฐ ๋‚˜๋ˆ—์…ˆ ์ •์˜๊ฐ€ ์•ˆ๋˜๋ฏ€๋กœ J(A,B) = 1 ์„ ๋”ฐ๋กœ ์ •์˜ํ•˜๋ผ.

 

์ž…๋ ฅ๊ฐ’

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

 

 

์ถœ๋ ฅ๊ฐ’

  • 0 - 1 ์‚ฌ์ด ์‹ค์ˆ˜์— 65536 ๊ณฑํ•œ ํ›„ ์ •์ˆ˜๋ถ€๋งŒ ์ถœ๋ ฅ.

 

 

 

 

๋ฌธ์ œํ’€์ด

 

 

์šฐ์„  ๋ฌธ์ž์—ด์—์„œ ์›์†Œ๋ฅผ ๋ฝ‘์•„ ์›์†Œ - ์›์†Œ๊ฐฏ์ˆ˜๋ฅผ ๋งคํ•‘ํ•˜๋Š” ํ•จ์ˆ˜ tokenize๋ฅผ ์ •์˜ํ–ˆ๋‹ค. ๋ฌธ์ œํ’€์ด์˜ ํŽธ์˜์ƒ token๋“ค์˜ ์ด ๊ฐฏ์ˆ˜๋„ ํ•จ๊ป˜ ๋ฐ˜ํ™˜ํ–ˆ๋‹ค. 
'A์ง‘ํ•ฉ + B์ง‘ํ•ฉ - A์™€ B์˜ ๊ต์ง‘ํ•ฉ = ํ•ฉ์ง‘ํ•ฉ'์ด๋ฏ€๋กœ ๊ต์ง‘ํ•ฉ์˜ ํฌ๊ธฐ๋งŒ ๊ตฌํ–ˆ๋‹ค.

 

 

์‹œ๊ฐ„๋ณต์žก๋„: O(s1 + s2)

๊ณต๊ฐ„๋ณต์žก๋„: O(s1 + s2)