user-img
์ „์—ญ ๋ณ€์ˆ˜ 1
thumbnail
[์•Œ๊ณ ๋ฆฌ์ฆ˜] LeetCode์—์„œ ์ „์—ญ ๋ณ€์ˆ˜ (static) ์“ธ ๋•Œ ์ดˆ๊ธฐํ™” ๊ผญ ํ•ด์ค˜์•ผ ํ•ด์š”!
1. ๊ฒช์—ˆ๋˜ ๋ฌธ์ œLeetCode ๋ฌธ์ œ๋ฅผ ํ’€๋ฉฐ, ๋กœ์ง์ด ๋งž๋Š” ๊ฒƒ ๊ฐ™์€๋ฐ๋„, ์ œ์ถœ ์‹œ ๊ณ„์† ๋‹ต์ด ํ‹€๋ฆฌ๊ฒŒ ๋‚˜์™€์„œ, Debuging์„ ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.์ œ๊ฐ€ ํ’€์—ˆ๋˜ ๋ฌธ์ œ๋Š” ์ด๊ฒƒ์ž…๋‹ˆ๋‹ค.๋ฌธ์ œ๋ฅผ ์•ˆ ํ‘ธ์…”๋„ ์•Œ ์ˆ˜ ์žˆ๊ฒŒ ๊ฐ„๋‹จํžˆ ๋ง์”€๋“œ๋ฆฌ๋ฉด,target์— ์žˆ๋Š” ๊ฐ’์„ key = target[i], value = i ๋กœ ํ•ด์„œ map์— ์ง‘์–ด๋„ฃ์œผ๋ ค๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค. target์˜ ๊ฐ’์€ ๋‹ค์Œ๊ณผ ๊ฐ™์•˜์Šต๋‹ˆ๋‹ค.target = [5,10,8,11,3,15,9,20,18,13]๊ทผ๋ฐ System.out.println()์œผ๋กœ ์ฐ์–ด๋ณด๋‹ˆ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‚˜์™”์Šต๋‹ˆ๋‹ค!{1=3, 2=5, 3=4, 4=1, 5=0, 6=0, 8=2, 9=6, 10=1, 11=3, 13=9, 15=5, 18=8, 20=7}target์— ์—†๋Š” 1์ด๋‚˜ 2 ๊ฐ™์€ ๊ฐ’์ด ๋“ค์–ด์žˆ๋˜ ๊ฒƒ์ž…๋‹ˆ๋‹ค. m..
2024.08.20
๊ฒช์€ ์˜ค๋ฅ˜์™€ ํ•ด๊ฒฐ์ฑ