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

์ž๋ฐ”11

[์ž๋ฐ”] Leetcode 1302 - Deepest Leaves Sum leetcode.com/problems/deepest-leaves-sum/ Deepest Leaves Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ๊ฐ€์žฅ ์•„๋ž˜์— ์žˆ๋Š” ๋…ธ๋“œ๋“ค์˜ value๊ฐ’์„ ํ•ฉํ•˜๋Š” ๋ฌธ์ œ๋‹ค. '์ฒ˜์Œ๋ถ€ํ„ฐ ๋„ˆ๋ฌด ๋งŽ์€ ์ƒ๊ฐ์„ ํ•˜์ง€ ๋ง์ž!'๊ณ  ๊ฒฐ์‹ฌํ•˜๊ณ  ์ •๋ง ๋– ์˜ค๋ฅด๋Š” ๋Œ€๋กœ ๋ฌธ์ œ๋ฅผ ํ’€์—ˆ๋”๋‹ˆ ํ†ต๊ณผ๋Š” ํ–ˆ๋Š”๋ฐ ์• ์ž”ํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์™”๋‹ค ใ…‹ใ…‹ใ…‹ Solution ๋‚˜๋ฆ„์˜ BFS๋กœ ๊ฐ€์žฅ ์•„๋ž˜์˜ ๋…ธ๋“œ๊ฐ€ ๋ช‡ depth์— ์žˆ๋Š”์ง€ ์ฐพ๊ณ , ๋‹ค์‹œ ํ•œ๋ฒˆ Queue๋ฅผ ๋Œ๋ฆฌ๋ฉด์„œ ํ•ด.. 2021. 4. 11.
[์ž๋ฐ”] ๋ฆฌํŠธ์ฝ”๋“œ 706 - Design HashMap HashMap์€ Map์„ ๊ตฌํ˜„ํ•œ ํด๋ž˜์Šค์ด๊ธฐ ๋•Œ๋ฌธ์—, ํ˜•ํƒœ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด๊ฐ„๋‹ค. ํ•ญ์ƒ ์ฃผ์–ด์ง„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉ๋งŒ ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์—, ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„๋˜์–ด ์žˆ๋Š”์ง€์— ๋Œ€ํ•ด์„œ๋Š” ๊ณ ๋ฏผํ•ด๋ณด์ง€ ์•Š์•˜๋Š”๋ฐ ๋•๋ถ„์— bucket์ด๋ผ๋Š” ๊ฐœ๋…๋„ ์•Œ๊ฒŒ ๋˜์—ˆ๋‹ค. ์ด๋ฒˆ ๋ฌธ์ œ๋Š” ๊ณต๋ถ€ํ•˜๋Š” ์ฐจ์›์—์„œ ํ‘ผ ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์—, ๋ฐ”๋กœ ํ’€์ด๋“ค์„ ์ข€ ์ฐพ์•„ ๋ณด์•˜๋‹ค. ์ฒซ ๋ฒˆ์งธ Solution ์–ด์ฐจํ”ผ key์˜ ๋ฒ”์œ„๊ฐ€ 0๋ถ€ํ„ฐ 1,000,000, ์ฆ‰ ๋ฐฑ๋งŒ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ด์„œ ๊ตฌํ˜„ํ•ด๋„ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค. MyHashMap ํด๋ž˜์Šค ์ƒ์„ฑ ์‹œ์—, ํฌ๊ธฐ 1000001์ธ ๋ฐฐ์—ด์„ ์„ ์–ธํ•œ ๋‹ค์Œ์— index๋ฅผ ํ‚ค๊ฐ’์ฒ˜๋Ÿผ ์ƒ๊ฐํ•ด์„œ ๊ตฌํ˜„ํ•˜๋ฉด ๋œ๋‹ค. ์‹œ๊ฐ„ ๋ณต์žก๋„ : O(1) (get, remove, put ๋ชจ๋‘์— ํ•ด๋‹น๋œ๋‹ค) ๊ณต๊ฐ„ ๋ณต์žก๋„ : O(n) class MyHashMap { int[] .. 2021. 3. 7.
[์ž๋ฐ”] Leetcode 637 - Average of Levels in Binary Tree leetcode.com/problems/average-of-levels-in-binary-tree/ Average of Levels in Binary Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ๊ธฐ์ดˆ BFS๋ฌธ์ œ์ธ๋ฐ, BFS๋กœ ํ’€ ์ˆ˜ ์žˆ์Œ์„ ํŒŒ์•…ํ•˜๋Š” ๋ฐ ์˜ค๋ž˜ ๊ฑธ๋ ธ๋‹ค. ์Šฌํ”„๋‹ค. root๋ฅผ Queue queue์— ๋„ฃ์€ ๋‹ค์Œ์—, ํ•˜๋‚˜์”ฉ ๋ฝ‘์œผ๋ฉด์„œ left์™€ right ๋…ธ๋“œ๋ฅผ ๋‹ค์‹œ queue์— ๋„ฃ์–ด์ค€๋‹ค. while๋ฌธ์„ ํƒ€๋ฉด์„œ ํ•œ ๋ ˆ๋ฒจ์˜ ๋…ธ๋“œ๊ฐœ์ˆ˜๊ฐ€ ๋ณ€์ˆ˜ siz.. 2021. 3. 5.
[์ž๋ฐ”] Leetcode 268 - Missing Number ๋ฌธ์ œ ๋ฐฐ์—ด nums๊ฐ€ ์ฃผ์–ด์ง€๋Š”๋ฐ, ์ด๋•Œ ๋ฐฐ์—ด์—๋Š” ๋ฒ”์œ„ [0,n]์— ์†ํ•˜๋Š” n๊ฐœ์˜ ์ˆซ์ž๊ฐ€ ๋‹ด๊ฒจ์žˆ๋‹ค. ๋ฒ”์œ„๊ฐ€ [0,n]์ด๋ผ๋ฉด ์ด n-1๊ฐœ์˜ ์ˆซ์ž๊ฐ€ ์žˆ์–ด์•ผํ•˜๋Š”๋ฐ, n๊ฐœ๋งŒ ๋‹ด๊ฒจ์žˆ๋‹ค๋Š” ๊ฑด ์ˆซ์ž ํ•œ๊ฐœ๊ฐ€ ๋น ์ ธ์žˆ๋‹ค๋Š” ๋œป. ๋น ์ง„ ์ˆซ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฌธ์ œ๋‹ค. leetcode.com/problems/missing-number/ Missing Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ์ฒซ ๋ฒˆ์งธ Solution ์‰ฝ๊ฒŒ ์ƒ๊ฐํ–ˆ๋‹ค. ๊ธธ์ด n์„ ๊ฐ€์ง€๋Š” boolean ๋ฐฐ์—ด์„ ๋งŒ.. 2021. 3. 4.