[Hyun] Week 6 Solution Explanation #123
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
11. Container With Most Water
Complexities ๐
Explanation ๐
ํฌ ํฌ์ธํฐ๋ฅผ ํ์ฉํด์ ๋ฌธ์ ๋ฅผ ํ์์ต๋๋ค.
left, right๋ฅผ ๊ฐ๊ฐ ๋ฐฐ์ด์ ์ฒซ ๋ฒ์งธ, ๋ง์ง๋ง ์์์ ์ ๊ทผํ ์ ์๋ ์ธ๋ฑ์ค๋ก ์ค์ ํ ๋ค
๋ ์ฌ์ด์ ๋์ด(
(right - left) * min(height[left], height[right])
)๋ฅผ ๊ตฌํ๊ณ ์ ๋ต ๋ณ์์ ์ต๋๊ฐ์ ์ค์ ํ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํํ์ต๋๋ค.๊ทธ ์ค์์ height[left]์ height[right] ์ค ๊ฐ์ฅ ์์ ๊ฐ์ ๊ฐ์ง ํฌ์ธํฐ๋ฅผ ์ฐพ์ ๊ฐ๊ฐ์์ผ๊ฐ๋ฉด์ ๊ฐ์ ์กฐ์ ํ์ต๋๋ค.
3. Longest Substring Without Repeating Characters
Complexities ๐
Explanation ๐
๋ฌธ์์ด์ ๋ฐฐ์ด๋ก ๋ง๋ค๊ณ , ์์ผ๋ก substring๊ฐ์ ์์์ ์ฅํ Setํ์ ์ ๋ง๋ ๋ค ๊ฐ ๋ฌธ์๋ฅผ ํ์ธํด๋๊ฐ๋ฉฐ ๊ธด longest substring์ ์ฒดํฌํ์ต๋๋ค.
Tip
Q: ์ฌ๊ธฐ์ ์ ๊น! ๋ฌธ์์ด์ ์ ๋ฐฐ์ด๋ก ๋ง๋์ จ๋์?
A: Swift์ ๋ฌธ์์ด ์ฒ๋ฆฌ๊ฐ ๊ฝค๋ ๋๋ฆฌ๊ธฐ ๋๋ฌธ์, ๋ฌธ์์ด์ ๋ฐฐ์ด๋ก ์ด๊ธฐํํด์ค ๋ค Int๊ฐ์ index๋ก ๋ฐฐ์ด์ ์ ๊ทผํ๋ ๊ฒ์ด ์๊ฐ ํจ์จ์ ์ข์ต๋๋ค.
์ฐธ๊ณ ๋ก Swift์
String
ํ์ ์ Intํ์ ์ผ๋ก ์ธ๋ฑ์ค ์ ๊ทผ์ด ๋์ง ์์ต๋๋ค. ใ ใ ..424. Longest Repeating Character Replacement
Complexities ๐
Explanation ๐
Sliding Window ๊ธฐ๋ฒ์ผ๋ก ํด๊ฒฐํ์ต๋๋ค.
์์ง ์ต์์น ์์์ Solution ๋ณด๋ฉด์ ํด๊ฒฐํ๋ค์. ใ ใ
153. Find Minimum in Rotated Sorted Array
Complexities ๐
Explanation ๐
์ต์ ๊ฐ์ ๊ตฌํ๋ ๊ฒ์ด๋ค๋ณด๋$O(n)$ ์ผ๋ก ์ต์๊ฐ์ ๊ตฌํด๋ ๋์ง๋ง, ์ด๋ถํ์์ ์ฌ์ฉํ์ฌ ์ํ๋ ์ต์๊ฐ์ ๊ตฌํ ์ ์๋ค๋ ์ ์ ์ฐธ๊ณ ํ์ฌ ๊ตฌํํ์ต๋๋ค. ์ด ํด๊ฒฐ๋ฐฉ๋ฒ์ผ๋ก $O(log n)$ ๋งํผ์ ์ต์ ํ๋ฅผ ํ ์ ์์์ต๋๋ค.
33. Search in Rotated Sorted Array
Complexities ๐
Explanation ๐
์ด๋ถํ์ ์ ๊ทผ์ ์ข ์ด๋ ค์์ ๊ฒช์ด์ ํ์ด๋ฒ์ ๋ณด๊ณ ํด๊ฒฐํ์ต๋๋ค ใ ใ ..