user-img
๋‘ ์šฉ์•ก java 1
thumbnail
[๋ฐฑ์ค€] ๋‘ ์šฉ์•ก java ์‰ฌ์šด ํ’€์ด^^
1. ๋ฌธ์ œ ์„ค๋ช… ๐Ÿ“Œ๋ฌธ์ œ ๋งํฌ์šฉ์•ก๋งˆ๋‹ค ํŠน์ˆ˜๊ฐ’์ด ์กด์žฌ๋‘ ์šฉ์•ก์„ ๊ณจ๋ผ์„œ ๋‘˜์˜ ํŠน์ˆ˜ ๊ฐ’์„ ํ•ฉํ–ˆ์„ ๋•Œ, ๊ทธ ํ•ฉ์ด 0์— ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์กฐํ•ฉ์„ ๊ตฌํ•˜์—ฌ๋ผ2. ์ ‘๊ทผ ๋ฐฉ์‹ ๐Ÿ—ƒ๏ธKEY WORD: Two way Two pointer์šฉ์•ก์˜ ํŠน์ˆ˜๊ฐ’์„ 1์ฐจ์› ๋ฐฐ์—ด์— ์ž…๋ ฅ๋ฐ›๊ณ , ํ•ด๋‹น ๋ฐฐ์—ด์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.index = 0์— L ํฌ์ธํ„ฐ, index = N-1์— R ํฌ์ธํ„ฐ๋ฅผ ๋‘”๋‹คL+R > 0 ์ผ ๊ฒฝ์šฐ, R ํฌ์ธํ„ฐ๋ฅผ ํ•œ ์นธ ํ›„์ง„ ์‹œ์ผœ์„œ ํ•ฉ์„ ํ•˜ํ–ฅ์กฐ์ •ํ•œ๋‹ค.L-R ์ผ ๊ฒฝ์šฐ, L ํฌ์ธํ„ฐ๋ฅผ ํ•œ ์นธ ์ „์ง„ ์‹œ์ผœ์„œ ํ•ฉ์„ ์ƒํ–ฅ์กฐ์ •ํ•œ๋‹ค.0์— ๊ฐ€๊นŒ์šด ๊ฐ’์„ ๊ตฌํ•ด์•ผํ•จ์œผ๋กœ, ๋‘˜ ์‚ฌ์ด์˜ ํ•ฉ์˜ ์ ˆ๋Œ€๊ฐ’์ด ์ตœ์†Œ์ธ ๊ฒฝ์šฐ๋ฅผ ์ฐพ์œผ๋ฉด ๋œ๋‹ค.(์™œ๋ƒํ•˜๋ฉด, ๋‘ ํฌ์ธํ„ฐ ์‚ฌ์ด์˜ ํ•ฉ์˜ ์ ˆ๋Œ€๊ฐ’์ด ์ปค์งˆ์ˆ˜๋ก 0์—์„œ ๋ฉ€์–ด์ง€๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.)(1) ๋‹จ๋ฑกํ•ญ ํˆฌ ํฌ์ธํ„ฐ๋กœ ๋‹ต์„ ๊ตฌํ•  ์ˆ˜ ์—†๋Š” ..
2024.12.23
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด