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

IN DEPTH CAKE/Supercoder

(25)
[์ฝ”๋”ฉ/LeetCode150-(9)] 55. Jump Game ๋ณธ ๊ธ€์€ LeetCode Top Interview 150์— ์ •๋ฆฌ๋œ ๋ฌธ์ œ๋ฅผ ์š”์•ฝํ•˜๊ณ  ์ด์— ๋Œ€ํ•œ ๊ฐœ์ธ์ ์ธ ํ’€์ด๋ฅผ ํฌํ•จํ•˜๊ณ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณธ ํฌ์ŠคํŒ… ์‹œ๋ฆฌ์ฆˆ๋Š” 150 list์˜ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฒŒ์žฌ๋ฉ๋‹ˆ๋‹ค. ํ’€์ด ์–ธ์–ด๋Š” python์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‚œ์ด๋„: Medium ํ‚ค์›Œ๋“œ: Array, DP ๋ฌธ์ œ ๋ฌธ์ œ ์›๋ฌธ: https://leetcode.com/problems/jump-game/description/?envType=study-plan-v2&envId=top-interview-150 ์ •์ˆ˜ํ˜• ๋ฐฐ์—ด nums๊ฐ€ ์ฃผ์–ด์กŒ๋‹ค๊ณ  ํ•˜์ž. ๋‹น์‹ ์€ ์ฒ˜์Œ์— ๋ฐฐ์—ด์˜ ์ฒซ๋ฒˆ์งธ index์— ์œ„์น˜ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋ฐฐ์—ด์˜ ๊ฐ ์›์†Œ๋Š” ํ•ด๋‹น ์œ„์น˜์—์„œ๋ถ€ํ„ฐ ๋‹น์‹ ์ด ์ตœ๋Œ€๋กœ ์ ํ”„ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธธ์ด๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. ์ด ๋•Œ, ๋งˆ์ง€๋ง‰ index ์— ๋„๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ t..
[์ฝ”๋”ฉ/LeetCode150-(8)] Best Time to Buy and Sell Stock II (122) ๋ณธ ๊ธ€์€ LeetCode Top Interview 150์— ์ •๋ฆฌ๋œ ๋ฌธ์ œ๋ฅผ ์š”์•ฝํ•˜๊ณ  ์ด์— ๋Œ€ํ•œ ๊ฐœ์ธ์ ์ธ ํ’€์ด๋ฅผ ํฌํ•จํ•˜๊ณ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณธ ํฌ์ŠคํŒ… ์‹œ๋ฆฌ์ฆˆ๋Š” 150 list์˜ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฒŒ์žฌ๋ฉ๋‹ˆ๋‹ค. ํ’€์ด ์–ธ์–ด๋Š” python์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‚œ์ด๋„: Medium ํ‚ค์›Œ๋“œ: Array, Greedy ๋ฌธ์ œ ๋ฌธ์ œ ์›๋ฌธ: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/?envType=study-plan-v2&envId=top-interview-150 prices๋ผ๋Š” ๋ฐฐ์—ด์ด ์ฃผ์–ด์ง„๋‹ค๊ณ ํ•˜์ž. ์ด ๋ฐฐ์—ด์˜ i๋ฒˆ์งธ ์›์†Œ๋“ค์€ ์ฃผ์‹์˜ ๊ฐ€๊ฒฉ์„ ์˜๋ฏธํ•œ๋‹ค. ํ•œ ๋ฒˆ์— ํ•˜๋‚˜์˜ ์ฃผ์‹๋งŒ ๊ฐ€์ง€๊ณ  ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค. ๋‹จ, ์ฃผ์‹์„ ํŒ”์ž๋งˆ์ž ๋‹น์ผ์— ๋ฐ”๋กœ ์‚ด ์ˆ˜ ์žˆ๋‹ค. ..
[์ฝ”๋”ฉ/LeetCode150-(7)] Best Time to Buy and Sell Stock (121) ๋ณธ ๊ธ€์€ LeetCode Top Interview 150์— ์ •๋ฆฌ๋œ ๋ฌธ์ œ๋ฅผ ์š”์•ฝํ•˜๊ณ  ์ด์— ๋Œ€ํ•œ ๊ฐœ์ธ์ ์ธ ํ’€์ด๋ฅผ ํฌํ•จํ•˜๊ณ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณธ ํฌ์ŠคํŒ… ์‹œ๋ฆฌ์ฆˆ๋Š” 150 list์˜ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฒŒ์žฌ๋ฉ๋‹ˆ๋‹ค. ํ’€์ด ์–ธ์–ด๋Š” python์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‚œ์ด๋„: EASY ํ‚ค์›Œ๋“œ: Array ๋ฌธ์ œ ๋ฌธ์ œ ์›๋ฌธ: https://leetcode.com/problems/best-time-to-buy-and-sell-stock/?envType=study-plan-v2&envId=top-interview-150 prices๋ผ๋Š” ๋ฐฐ์—ด์ด ์ฃผ์–ด์ง„๋‹ค๊ณ ํ•˜์ž. ์ด ๋ฐฐ์—ด์˜ i๋ฒˆ์งธ ์›์†Œ๋“ค์€ ์ฃผ์‹์˜ ๊ฐ€๊ฒฉ์„ ์˜๋ฏธํ•œ๋‹ค. ์ด ๋•Œ ์—ฌ๋Ÿฌ๋ถ„์€ ์ฃผ์‹์„ ์‚ฌ๋Š” ๋‚ ๊ณผ ํŒŒ๋Š” ๋‚ ์„ ์ •ํ•˜๋ ค๊ณ ํ•œ๋‹ค. ๊ฐ€๋Šฅํ•œ ๊ฑฐ๋ž˜ ๊ฒฝ์šฐ์˜ ์ˆ˜ ์ค‘ ์ตœ๋Œ€ ์ด์œค ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๋ผ. (๋„ˆ๋ฌด ๋‹น์—ฐํ•˜๊ฒŒ๋„ ๋งค๋„๋Š” ๋งค..
[์ฝ”๋”ฉ/LeetCode150-(6)] Rotate Array (189) ๋ณธ ๊ธ€์€ LeetCode Top Interview 150์— ์ •๋ฆฌ๋œ ๋ฌธ์ œ๋ฅผ ์š”์•ฝํ•˜๊ณ  ์ด์— ๋Œ€ํ•œ ๊ฐœ์ธ์ ์ธ ํ’€์ด๋ฅผ ํฌํ•จํ•˜๊ณ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณธ ํฌ์ŠคํŒ… ์‹œ๋ฆฌ์ฆˆ๋Š” 150 list์˜ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฒŒ์žฌ๋ฉ๋‹ˆ๋‹ค. ํ’€์ด ์–ธ์–ด๋Š” python3์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‚œ์ด๋„: Medium ํ‚ค์›Œ๋“œ: Array ๐Ÿ”’ ๋ฌธ์ œ ๋ฌธ์ œ ์›๋ฌธ: https://leetcode.com/problems/rotate-array/description/?envType=study-plan-v2&envId=top-interview-150 ์ •์ˆ˜ ๋ฐฐ์—ด nums๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ์ฃผ์–ด์ง„ ์Œ์ด ์•„๋‹Œ ์ •์ˆ˜ k์— ๋Œ€ํ•ด์„œ k ๋ฒˆ๋งŒํผ ๋ฐฐ์—ด์„ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ํšŒ์ „์‹œ์ผœ๋ผ ๐Ÿงช ์˜ˆ์ œ Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Expla..
[์ฝ”๋”ฉ/LeetCode150-(5)] Majority Element (169) ๋ณธ ๊ธ€์€ LeetCode Top Interview 150์— ์ •๋ฆฌ๋œ ๋ฌธ์ œ๋ฅผ ์š”์•ฝํ•˜๊ณ  ์ด์— ๋Œ€ํ•œ ๊ฐœ์ธ์ ์ธ ํ’€์ด๋ฅผ ํฌํ•จํ•˜๊ณ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณธ ํฌ์ŠคํŒ… ์‹œ๋ฆฌ์ฆˆ๋Š” 150 list์˜ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฒŒ์žฌ๋ฉ๋‹ˆ๋‹ค. ํ’€์ด ์–ธ์–ด๋Š” python์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‚œ์ด๋„: EASY ํ‚ค์›Œ๋“œ: Array, Hash Table ๋ฌธ์ œ ๋ฌธ์ œ ์›๋ฌธ: https://leetcode.com/problems/majority-element/description/ ํฌ๊ธฐ๊ฐ€ n์ธ ๋ฐฐ์—ด nums๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ตœ๋นˆ๋„ (the majority) ์›์†Œ๋ฅผ ๋ฐ˜ํ™˜ํ•ด๋ผ. ์ตœ๋นˆ (majority) ์›์†Œ๋Š” ํ•ญ์ƒ ์กด์žฌํ•˜๋ฉฐ, ์ด ์›์†Œ์˜ ์ˆ˜๋Š” ๋ฐฐ์—ด ๊ธธ์ด์˜ ์ ˆ๋ฐ˜์„ ๋„˜๋Š”๋‹ค. ์˜ˆ์ œ Input: nums = [3,2,3] Output: 3 Input: nums = [2,2,1,1,1,2..
[์ฝ”๋”ฉ/LeetCode150-(4)] Remove Duplicates from Sorted Array II(80) ๋ณธ ๊ธ€์€ LeetCode Top Interview 150์— ์ •๋ฆฌ๋œ ๋ฌธ์ œ๋ฅผ ์š”์•ฝํ•˜๊ณ  ์ด์— ๋Œ€ํ•œ ๊ฐœ์ธ์ ์ธ ํ’€์ด๋ฅผ ํฌํ•จํ•˜๊ณ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณธ ํฌ์ŠคํŒ… ์‹œ๋ฆฌ์ฆˆ๋Š” 150 list์˜ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฒŒ์žฌ๋ฉ๋‹ˆ๋‹ค. ํ’€์ด ์–ธ์–ด๋Š” python์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‚œ์ด๋„: MEDIUM ํ‚ค์›Œ๋“œ: Array, Two-Pointers ๋ฌธ์ œ ๋ฌธ์ œ์›๋ฌธ: https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/description/?envType=study-plan-v2&envId=top-interview-150 ์ฃผ์–ด์ง„ ๊ฐ์†Œํ•˜์ง€ ์•Š๋Š” ์ˆœ์„œ๋กœ ์ •๋ ฌ๋œ ์ •์ˆ˜ ๋ฐฐ์—ด nums์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ๋™์ผํ•œ ๊ฐ’์ด ์ตœ๋Œ€ ๋‘๋ฒˆ๋งŒ ๋ฐ˜๋ณต๋˜๋„๋ก in-placeํ˜•ํƒœ๋กœ nums๋ฅผ ์—…๋ฐ์ดํŠธํ•ด๋ผ. (๋‹ค์‹œ ๋งํ•ด, 3..
[์ฝ”๋”ฉ/LeetCode150-(3)] Remove Duplicates from Sorted Array (26) ๋ณธ ๊ธ€์€ LeetCode Top Interview 150์— ์ •๋ฆฌ๋œ ๋ฌธ์ œ๋ฅผ ์š”์•ฝํ•˜๊ณ  ์ด์— ๋Œ€ํ•œ ๊ฐœ์ธ์ ์ธ ํ’€์ด๋ฅผ ํฌํ•จํ•˜๊ณ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณธ ํฌ์ŠคํŒ… ์‹œ๋ฆฌ์ฆˆ๋Š” 150 list์˜ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฒŒ์žฌ๋ฉ๋‹ˆ๋‹ค. ํ’€์ด ์–ธ์–ด๋Š” python์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‚œ์ด๋„: EASY ํ‚ค์›Œ๋“œ: Array, Two-Pointers ๋ฌธ์ œ ๋ฌธ์ œ์›๋ฌธ: https://leetcode.com/problems/remove-duplicates-from-sorted-array/?envType=study-plan-v2&envId=top-interview-150 ์ฃผ์–ด์ง„ ๊ฐ์†Œํ•˜์ง€ ์•Š๋Š” ์ˆœ์„œ๋กœ ์ •๋ ฌ๋œ ์ •์ˆ˜ ๋ฐฐ์—ด nums์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ์˜ค์ง uniqueํ•œ ๊ฐ’๋งŒ ์žˆ๋„๋ก in-placeํ˜•ํƒœ๋กœ nums๋ฅผ ์—…๋ฐ์ดํŠธํ•ด๋ผ. (๋‹ค์‹œ ๋งํ•ด, ์ค‘๋ณต๋œ ๊ฐ’์„ ์ œ๊ฑฐํ•ด๋ผ) ์ด ๋•Œ ๊ฐ’๋“ค์˜..
[์ฝ”๋”ฉ/LeetCode150-(2)] Remove Element (27) ๋ณธ ๊ธ€์€ LeetCode Top Interview 150์— ์ •๋ฆฌ๋œ ๋ฌธ์ œ๋ฅผ ์š”์•ฝํ•˜๊ณ  ์ด์— ๋Œ€ํ•œ ๊ฐœ์ธ์ ์ธ ํ’€์ด๋ฅผ ํฌํ•จํ•˜๊ณ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณธ ํฌ์ŠคํŒ… ์‹œ๋ฆฌ์ฆˆ๋Š” 150 list์˜ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฒŒ์žฌ๋ฉ๋‹ˆ๋‹ค. ํ’€์ด ์–ธ์–ด๋Š” python3์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋‚œ์ด๋„: EASY ํ‚ค์›Œ๋“œ: Array, Two-Pointers ๋ฌธ์ œ ๋ฌธ์ œ ์›๋ฌธ: https://leetcode.com/problems/remove-element/?envType=study-plan-v2&envId=top-interview-150 ์ •์ˆ˜ ๋ฐฐ์—ด nums์™€ ์ •์ˆ˜ val ์ด ์ฃผ์–ด์กŒ์„ ๋•Œ nums ๋‚ด์— val ๊ฐ’์„ in-place ํ˜•ํƒœ๋กœ ์ œ๊ฑฐํ•ด๋ผ. ์ด ๋•Œ ์š”์†Œ (elements)๋“ค์˜ ์ˆœ์„œ๋Š” ๋ฐ”๋€” ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ด๋ ‡๊ฒŒ ์—…๋ฐ์ดํŠธ ๋œ nums ๋‚ด์˜ element์˜ ์ˆ˜๋ฅผ ๋ฐ˜..