user-img
๊ฐœ๋ฐœ์ž ์ทจ์—… 54
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
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด
thumbnail
[๋ฐฑ์ค€] 2003 ์ˆ˜๋“ค์˜ ํ•ฉ2 ์‰ฌ์šด ํ’€์ด java ^^
1. ๋ฌธ์ œ ์„ค๋ช… ๐Ÿ“Œ๋ฌธ์ œ ๋งํฌ2. ์ ‘๊ทผ ๋ฐฉ์‹ ๐Ÿ—ƒ๏ธKEY WORD: one-way Two pointer๋‹จ๋ฐฉํ–ฅ ํˆฌ ํฌ์ธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ „ํ˜•์ ์ธ ๋ฌธ์ œ์ด๋‹ค. ์™ผ์ชฝ ํฌ์ธํ„ฐ(L)๊ณผ ์˜ค๋ฅธ์ชฝ ํฌ์ธํ„ฐ(R)์„ ๋‘”๋‹ค. ํ•ด๋‹น ๊ตฌ๊ฐ„ ๋‚ด ์ˆ˜๋“ค์˜ ํ•ฉ์„ sum์ด๋ผ ํ•˜๊ฒ ๋‹ค.sum : R ํฌ์ธํ„ฐ๋ฅผ ์ „์ง„์‹œํ‚จ๋‹ค.sum >= M: L ํฌ์ธํ„ฐ๋ฅผ ์ „์ง„์‹œํ‚จ๋‹ค. (๋งŒ์•ฝ sum == M์ด๋ฉด ๋‹ต์ด ๋˜๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ +1 ์˜ฌ๋ฆฐ๋‹ค.)๊ตฌ๊ฐ„ ๋‚ด์˜ ํ•ฉ์€ ๊ตฌ๊ฐ„ ๋‚ด์˜ ๊ฐ’์ด ์›์†Œ ํ•˜๋‚˜์ธ ๊ฒฝ์šฐ๋„ ํฌํ•จํ•œ๋‹ค. ๋”ฐ๋ผ์„œ arr[0] == M ์ธ ๊ฒฝ์šฐ๋„ ์˜ˆ์™ธ ์—†์ด ๊ณ„์‚ฐ์— ํฌํ•จ๋˜๋„๋ก ํ•ด์ค˜์•ผ ํ•œ๋‹ค.๋‚˜๋Š” 3๋ฒˆ์˜ ๊ทœ์น™์„ ์ง€ํ‚ค๊ธฐ ์œ„ํ•ด ๋ฐฐ์—ด์„ N+1๋กœ ๋งŒ๋“ค์–ด ๊ฐ’๋“ค์„ 1๋ถ€ํ„ฐ ์ฑ„์šฐ๊ณ , ํฌ์ธํ„ฐ๋“ค์€ 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋„๋ก ํ•˜์˜€๋‹ค.3. ์ฝ”๋“œ ์†Œ๊ฐœ ๐Ÿ”Žimport java.io.*;import java..
2024.12.23
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด
thumbnail
ํˆฌ ํฌ์ธํ„ฐ ๊ฐœ๋… ๊ทธ๋ฆผ์œผ๋กœ ์‰ฝ๊ฒŒ ์„ค๋ช…^^
0. ๊ธ€์ด ํ˜๋Ÿฌ๊ฐ€๋Š” ๋ฐฉํ–ฅ๋จผ์ € ๊ฐœ๋… ์„ค๋ช…์„ ํ•˜๊ณ , ํˆฌ ํฌ์ธํ„ฐ๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋Œ€ํ‘œ์ ์ธ ๋ฌธ์ œ 2๊ฐœ๋ฅผ ์ง์ ‘ ํ’€์–ด๋ณด๋ฉฐ, ๊ฐœ๋…์— ๋Œ€ํ•œ ๋ณด์ถฉ์„ ํ•˜๊ฒ ๋‹ค.1. ๊ฐœ๋…1์ฐจ์› ๋ฐฐ์—ด์— ๋‘ ๊ฐœ์˜ ํฌ์ธํ„ฐ๋ฅผ ๋‘๊ณ , ๋‘ ํฌ์ธํ„ฐ์— ์˜๋ฏธ๋ฅผ ๋ถ€์—ฌํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ‘ธ๋Š” ๊ธฐ์ˆ ๋ฐฐ์—ด ์•ˆ์—์„œ ํŠน์ • ์กฐ๊ฑด์˜ ๊ฐ’์„ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ์—์„œ, ์ผ๋ฐ˜์ ์œผ๋กœ ์‹œ๊ฐ„ ๋ณต์žก๋„๊ฐ€ O((N^{2}))๊ฐ€ ๋“ ๋‹ค๋ฉด, ํˆฌ ํฌ์ธํ„ฐ ๊ธฐ๋ฒ•์„ ํ™œ์šฉํ•˜๋ฉด ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ O(N)์œผ๋กœ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค. (์ด์œ ๋Š” ํ™œ์šฉ์„ ์‚ดํŽด๋ณด๋ฉฐ ์„ค๋ช…ํ•˜๊ฒ ๋‹ค.)(1) ์œ ํ˜•ํˆฌ ํฌ์ธํ„ฐ๋ฅผ ์šด์šฉํ•˜๋Š” ์œ ํ˜•์—๋Š” ํฌ๊ฒŒ 2๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.a.๋‹จ๋ฐฉํ–ฅ ์šด์šฉL ํฌ์ธํ„ฐ์™€ R ํฌ์ธํ„ฐ๊ฐ€ ํ•œ์ชฝ ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ ์›€์ง์ด๋Š” ๊ฒƒ์ด๋‹ค. ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ์˜ ์–‘๋์„ ์˜๋ฏธํ•œ๋‹ค๊ณ  ๋ณด๋ฉด ๋œ๋‹ค. ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ์™€ ๋‹ค๋ฅธ ์ ์€ ํฌ์ธํ„ฐ์— ๋”ฐ๋ผ ๊ตฌ๊ฐ„์˜ ๊ธธ์ด๊ฐ€ ๊ฐ€๋ณ€์ ์ด๋ผ๋Š” ๊ฒƒ์ด๋‹ค.b. ์–‘๋ฐฉํ–ฅ ์šด..
2024.12.23
์•Œ๊ณ ๋ฆฌ์ฆ˜/์•Œ๊ณ ๋ฆฌ์ฆ˜-์ด๋ก 
thumbnail
[๋ฐฑ์ค€] 11003 ์ตœ์†Œ๊ฐ’ ์ฐพ๊ธฐ java ํ’€์ด (๊ทธ๋ฆผ์œผ๋กœ ์‰ฌ์šด ์„ค๋ช… ^^)
1. ๋ฌธ์ œ ์„ค๋ช… ๐Ÿ“Œ๋ฌธ์ œ ๋งํฌ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ์—์„œ ๋” ๋‚˜์•„๊ฐ€์„œ, ์œˆ๋„์šฐ ๊ตฌ๊ฐ„์•ˆ์— ์ตœ์†Œ๊ฐ’์„ ๋งค๋ฒˆ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค.2. ์ ‘๊ทผ ๋ฐฉ์‹ ๐Ÿ—ƒ๏ธKEY WORD: Sliding Window, Data Structure (Deque)ํŒŒ์ด์ฌ์—์„œ๋Š” ์ถ”๊ฐ€์‹œ๊ฐ„์ด ์ฃผ์–ด์ค˜์„œ ์šฐ์„ ์ˆœ์œ„ ํ๋ฅผ ์ด์šฉํ•ด๋„ ํ’€๋ฆฌ์ง€๋งŒ, Java์—์„œ๋Š” ํ’€๋ฆฌ์ง€ ์•Š๋Š”๋‹ค. ์™œ ์šฐ์„ ์ˆœ์œ„ ํ๋กœ๋Š” ์•ˆ๋˜๋Š”์ง€์— ๋Œ€ํ•ด 4๋ฒˆ ํ•ญ๋ชฉ์—์„œ ์„ค๋ช…ํ•˜๊ฒ ๋‹ค.(1) ์ „์ฒด ์ ‘๊ทผ ๋ฐฉ์‹ArrayDeque๋กœ ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค.(ํ•ด๋‹น deque๋Š” ํ˜„์žฌ ๊ตฌ๊ฐ„์ธ ๊ฐ’๋“ค๋งŒ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ, ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ๊ฐ’์˜ ์ˆœ์„œ๋ฅผ ์œ ์ง€ํ•œ๋‹ค. (front = ์ตœ์†Œ๊ฐ’))์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ๋ฅผ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ํ•œ ์นธ์”ฉ ์›€์ง์ธ๋‹ค.๊ตฌ๊ฐ„์— ์‹ ๊ทœ๋กœ ์ถ”๊ฐ€๋  ๊ฐ’์„ A๋ผ๊ณ  ์ณค์„ ๋•Œ, A์™€ deque์˜ rear(๊ผฌ๋ฆฌ)๋ฅผ ๋น„๊ตํ•œ๋‹คrear > A:..
2024.12.21
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด
thumbnail
[๋ฐฑ์ค€] 3020 ๊ฐœ๋˜ฅ๋ฒŒ๋ ˆ java ์™„๋ฒฝ ํ’€์ด!
1. ๋ฌธ์ œ ์„ค๋ช… ๐Ÿ“Œ๋ฌธ์ œ ๋งํฌ2. ์ ‘๊ทผ ๋ฐฉ์‹ ๐Ÿ—ƒ๏ธKEY WORD: ๋ˆ„์  ํ•ฉ, ์ด๋ถ„ ํƒ์ƒ‰๋™๊ตด์˜ ๋†’์ด์ธ H์™€ ๊นŠ์ด์ธ N์ด ๊ฐ๊ฐ \(10^{5}\)์ด๋ฏ€๋กœ, ์™„์ „ ํƒ์ƒ‰์œผ๋กœ ํ•˜๋‚˜์˜ ํ–‰๋งˆ๋‹ค ๋ชจ๋“  ์—ด์„ ์กฐํšŒํ•œ๋‹ค๋ฉด 1์ดˆ์— \(10^{10}\)๋ฒˆ ์ด์ƒ์˜ ์—ฐ์‚ฐ์„ ํ•ด์•ผํ•ด์„œ ์‹œ๊ฐ„ ์ดˆ๊ณผ๊ฐ€ ๋‚  ๊ฒƒ์ด๋‹ค.ํ•ด๋‹น ๋ฌธ์ œ๋Š” *๊ฑฐ๊พธ๋กœ ๋งค๋‹ฌ๋ ค ์žˆ๋Š” ์ข…์œ ์„์„ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•  ๊ฒƒ์ธ๊ฐ€?* ์— ๋Œ€ํ•œ ๋ช…ํ™•ํ•œ ๊ฐ€์ด๋“œ๋ผ์ธ๋งŒ ๊ณ„ํšํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ด๋‹ค. ์ข…์œ ์„ ์ฒ˜๋ฆฌ๋ฐฉ๋ฒ•์— ๋”ฐ๋ผ ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ํ’€ ์ˆ˜ ์žˆ๋Š”๋ฐ, ํ•˜๋‚˜๋Š” ๋ˆ„์  ํ•ฉ์ด๊ณ  ๋‹ค๋ฅธ ํ•˜๋‚˜๋Š” ์ด๋ถ„ ํƒ์ƒ‰์ด๋‹ค.(1) ๋ˆ„์ ํ•ฉa. ๊ฒฐ๋ก  ๋จผ์ €1. "์„์ˆœ๊ณผ ์ข…์œ ์„ ์ž…๋ ฅ์„ ๋ถ„๋ฅ˜ํ•˜์—ฌ Y์ถ• ์œ„์น˜์— ๋”ฐ๋ฅธ ๊ฐ ์‚ฐ๋ฌผ์˜ ์œ„์น˜๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐฐ์—ด ๊ตฌํ˜„"2. "๊ฐ ๋ฐฐ์—ด์˜ ๋ˆ„์ ํ•ฉ ๊ตฌํ•˜๊ธฐ (์„์ˆœ ๋ˆ„์ ํ•ฉ ๋ฐฐ์—ด์„ sum_S[i], ..
2024.12.19
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด
thumbnail
[๋ฐฑ์ค€] 16139 ์ธ๊ฐ„-์ปดํ“จํ„ฐ ์ƒํ˜ธ์ž‘์šฉ java ํ’€์ด
1. ๋ฌธ์ œ ์„ค๋ช… ๐Ÿ“Œ๋ฌธ์ œ ๋งํฌ2. ์ ‘๊ทผ ๋ฐฉ์‹ ๐Ÿ—ƒ๏ธKEY WORD: ๊ตฌ๊ฐ„ ํ•ฉ๋ˆ„์ ํ•ฉ ๋ฐฐ์—ด S์—์„œ A~B ๊ตฌ๊ฐ„ ๋‚ด์˜ ๊ตฌ๊ฐ„ํ•ฉ์„ ๊ตฌํ•  ๊ฒฝ์šฐ ์–ด๋–ป๊ฒŒ ํ‘œํ˜„ํ–ˆ๋Š”๊ฐ€?S[B] - S[A-1] ์ด์˜€๋‹ค. A๊ฐ€ ๊ตฌ๊ฐ„๋‚ด์— ํ•ฉํ•ด์ง€๋„๋ก A-1๊นŒ์ง€์˜ ๊ตฌ๊ฐ„ํ•ฉ์„ ์ œ๊ฑฐํ–ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์›๋ฆฌ๋Š” ๊ตฌ๊ฐ„ ๋‚ด์— ์•ŒํŒŒ๋ฒณ์ด ๋ช‡ ๋ฒˆ ๋“ฑ์žฅํ•˜๋Š”๊ฐ€ ์ฐพ๋Š” ์ด๋ฒˆ ๋ฌธ์ œ์—์„œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.์œ„ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด, a๊ฐ€ A๊ตฌ๊ฐ„์—์„œ ํ•œ๋ฒˆ, B๊ตฌ๊ฐ„์—์„œ ํ•œ๋ฒˆ ๋‚˜์˜จ๋‹ค๊ณ  ํ•˜์ž. ๊ทธ๋Ÿฌ๋ฉด, S[A] = 1, S[B] = 2๊ฐ€ ๋  ๊ฒƒ์ด๋‹ค. ๊ตฌ๊ฐ„์„ ํ™•์ธํ•˜๋ฉด ๋ฌธ์ž์—ด์ด A์˜ ์œ„์น˜๋ฅผ ๋„˜์–ด์„œ์„œ B๊นŒ์ง€ ๊ตฌ๊ฐ„์„ ์ •ํ•˜๋Š” ์ˆœ๊ฐ„ a๋Š” ํ•œ๊ฐœ์ด๋‹ค. S[B]-S[A]๋Š” A+1 ~ B๊นŒ์ง€์˜ ๊ตฌ๊ฐ„ํ•ฉ์ž„์œผ๋กœ 2-1 = 1์ด ๋‚˜์˜จ๋‹ค. ๋ฐ˜๋ฉด S[B] - S[A-1]์€ A์˜ ์œ„์น˜๋ถ€ํ„ฐ B๊นŒ์ง€์˜ ๊ฑฐ๋ฆฌ์—์„œ a์˜ ๊ฐœ์ˆ˜์ž„์œผ๋กœ S[..
2024.12.12
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด
thumbnail
โค๏ธ[๋ฐฑ์ค€] 2143 ๋‘ ๋ฐฐ์—ด์˜ ํ•ฉ java
1. ๋ฌธ์ œ ์„ค๋ช… ๐Ÿ“Œ๋ฌธ์ œ ๋งํฌ๋‘ ๋ฐฐ์—ด์˜ ๊ตฌ๊ฐ„ํ•ฉ๋ผ๋ฆฌ ๋”ํ•ด์„œ ๋ชฉํ‘œ๊ฐ’์ธ T๊ฐ€ ๋‚˜์˜ค๋Š” ํšŸ์ˆ˜๋ฅผ ์„ธ๋Š” ๋ฌธ์ œ2. ์ ‘๊ทผ ๋ฐฉ์‹ ๐Ÿ—ƒ๏ธKEY WORD: Two Pointer, Range sum์ด๋ฒˆ ๋ฌธ์ œ๋Š” ๊ฐ ๋ฐฐ์—ด์—์„œ ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋Š” ๊ตฌ๊ฐ„ํ•ฉ์„ ๋ชจ๋‘ ๊ตฌํ•ด์„œ List ํ™” ์‹œํ‚จ ๋’ค์—, ์ด ๋‘ List์—์„œ ๊ฐ’์„ ๊ฐ๊ฐ ๊บผ๋‚ด์–ด ๋ณด๋ฉฐ, T๊ฐ€ ๋  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ์„ธ์•ผํ•œ๋‹ค. ํ•œ๋งˆ๋””๋กœ ์š”์•ฝํ•˜๋ฉด ๊ตฌ๊ฐ„ํ•ฉ ํ›„๋ณด๊ตฐ๋“ค ์‚ฌ์ด์—์„œ Two Pointer๋กœ ์š”์•ฝํ•  ์ˆ˜ ์žˆ๋‹ค.(1) ์™œ ๊ทธ๋ ‡๊ฒŒ ํ’€์–ด์•ผ ํ•˜๋‚˜์š”?๋‹ต: ๋ฐฐ์—ด์˜ ์›์†Œ๋กœ ์Œ์ˆ˜๊ฐ€ ์กด์žฌ์ด ๋ฌธ์ œ์˜ ๊นŒ๋‹ค๋กœ์šด ์ ์€ ๋ฐฐ์—ด์˜ ์›์†Œ๋กœ ์Œ์ˆ˜๊ฐ€ ์กด์žฌํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ๋ˆ„์ ํ•ฉ์„ ํ™œ์šฉํ•œ ๊ตฌ๊ฐ„ํ•ฉ์„ ๊ตฌํ•˜๋Š”๋ฐ ๊ธฐ๋ณธ์ด ๋˜๋Š” ์ „์ œ ์กฐ๊ฑด์€ "right ํฌ์ธํ„ฐ๋ฅผ ๋Š˜๋ฆฌ๋ฉด ๊ตฌ๊ฐ„ํ•ฉ์ด ์ปค์ง„๋‹ค. left ํฌ์ธํ„ฐ๋ฅผ ๋Š˜๋ฆฌ๋ฉด ๊ตฌ๊ฐ„ํ•ฉ์ด ์ค„์–ด๋“ ๋‹ค...
2024.12.09
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด
thumbnail
โค๏ธ[๋ฐฑ์ค€] 1806 ๋ถ€๋ถ„ํ•ฉ java
1. ๋ฌธ์ œ ์„ค๋ช… ๐Ÿ“Œhttps://www.acmicpc.net/problem/1806 ๋ฌธ์ œ๊ฐ€ ์ง๊ด€์ ์ด๋ผ ์„ค๋ช… ์ƒ๋žต!2. ์ ‘๊ทผ ๋ฐฉ์‹ ๐Ÿ—ƒ๏ธKEY WORD: TWO POINTER๋ชฉํ‘œ๊ฐ’ ๋ณด๋‹ค Two Pointer ๊ตฌ๊ฐ„ ๋‚ด์˜ ํ•ฉ์ด ์ž‘์œผ๋ฉด ์˜ค๋ฅธ์ชฝ ํฌ์ธํ„ฐ ์ด๋™๋ชฉํ‘œ๊ฐ’ ๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด ์™ผ์ชฝ ํฌ์ธํ„ฐ ์ด๋™๊ตฌ๊ฐ„ ๋‚ด ํ•ฉ์ด ๋ชฉํ‘œ๊ฐ’ ์ด์ƒ์ด๋ฉด Math.min(์ด์ „๊นŒ์ง€์˜ ์ตœ์†Œ ๊ฐœ์ˆ˜, ํ˜„์žฌ ๊ฐœ์ˆ˜)๋กœ ์ตœ์†Œ๊ฐ’ ๊ฐฑ์‹ 3. ์ฝ”๋“œ ์†Œ๊ฐœ ๐Ÿ”Žimport java.io.*;import java.util.*;public class Main { /* * KEY WORD: ํˆฌ ํฌ์ธํ„ฐ * 1. ๋ชฉํ‘œ๊ฐ’๋ณด๋‹ค ์ž‘์œผ๋ฉด ์˜ค๋ฅธ์ชฝ ํฌ์ธํ„ฐ ์ด๋™ * 2. ๋ชฉํ‘œ๊ฐ’๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด ์™ผ์ชฝ ํฌ์ธํ„ฐ ์ด๋™ * 3. ๋ชฉํ‘œ๊ฐ’๊ณผ ์ผ์น˜ํ•˜๋ฉด ๊ทธ ๊ฐœ์ˆ˜๋ฅผ ๋ฝ‘์•„๋‚ด..
2024.12.07
์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฌธ์ œ ํ’€์ด