Skip to content

[Hyun] Week 6 Solution Explanation #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 10, 2024

Conversation

WhiteHyun
Copy link
Member

@WhiteHyun WhiteHyun commented Jun 8, 2024

11. Container With Most Water

Complexities ๐Ÿ“ˆ

  • Time Complexity: $O(n)$
  • Space Complexity: $O(1)$

Explanation ๐Ÿ“

ํˆฌ ํฌ์ธํ„ฐ๋ฅผ ํ™œ์šฉํ•ด์„œ ๋ฌธ์ œ๋ฅผ ํ’€์—ˆ์Šต๋‹ˆ๋‹ค.
left, right๋ฅผ ๊ฐ๊ฐ ๋ฐฐ์—ด์˜ ์ฒซ ๋ฒˆ์งธ, ๋งˆ์ง€๋ง‰ ์š”์†Œ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ์ธ๋ฑ์Šค๋กœ ์„ค์ •ํ•œ ๋’ค
๋‘ ์‚ฌ์ด์˜ ๋„“์ด((right - left) * min(height[left], height[right]))๋ฅผ ๊ตฌํ•˜๊ณ  ์ •๋‹ต ๋ณ€์ˆ˜์— ์ตœ๋Œ“๊ฐ’์„ ์„ค์ •ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.
๊ทธ ์ค‘์—์„œ height[left]์™€ height[right] ์ค‘ ๊ฐ€์žฅ ์ž‘์€ ๊ฐ’์„ ๊ฐ€์ง„ ํฌ์ธํ„ฐ๋ฅผ ์ฐพ์•„ ๊ฐ€๊ฐ์‹œ์ผœ๊ฐ€๋ฉด์„œ ๊ฐ’์„ ์กฐ์ ˆํ–ˆ์Šต๋‹ˆ๋‹ค.

3. Longest Substring Without Repeating Characters

Complexities ๐Ÿ“ˆ

  • Time Complexity: $O(n)$
  • Space Complexity: $O(n)$

Explanation ๐Ÿ“

๋ฌธ์ž์—ด์„ ๋ฐฐ์—ด๋กœ ๋งŒ๋“ค๊ณ , ์•ž์œผ๋กœ substring๊ฐ’์„ ์ž„์‹œ์ €์žฅํ•  Setํƒ€์ž…์„ ๋งŒ๋“  ๋’ค ๊ฐ ๋ฌธ์ž๋ฅผ ํ™•์ธํ•ด๋‚˜๊ฐ€๋ฉฐ ๊ธด longest substring์„ ์ฒดํฌํ–ˆ์Šต๋‹ˆ๋‹ค.

Tip

Q: ์—ฌ๊ธฐ์„œ ์ž ๊น! ๋ฌธ์ž์—ด์„ ์™œ ๋ฐฐ์—ด๋กœ ๋งŒ๋“œ์…จ๋‚˜์š”?
A: Swift์˜ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ๊ฐ€ ๊ฝค๋‚˜ ๋А๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์—, ๋ฌธ์ž์—ด์„ ๋ฐฐ์—ด๋กœ ์ดˆ๊ธฐํ™”ํ•ด์ค€ ๋’ค Int๊ฐ’์˜ index๋กœ ๋ฐฐ์—ด์— ์ ‘๊ทผํ•˜๋Š” ๊ฒƒ์ด ์‹œ๊ฐ„ ํšจ์œจ์— ์ข‹์Šต๋‹ˆ๋‹ค.
์ฐธ๊ณ ๋กœ Swift์˜ Stringํƒ€์ž…์€ Intํƒ€์ž…์œผ๋กœ ์ธ๋ฑ์Šค ์ ‘๊ทผ์ด ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ใ…Žใ…Ž..

424. Longest Repeating Character Replacement

Complexities ๐Ÿ“ˆ

  • Time Complexity: $O(n)$
  • Space Complexity: $O(1)$

Explanation ๐Ÿ“

Sliding Window ๊ธฐ๋ฒ•์œผ๋กœ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.
์•„์ง ์ต์ˆ™์น˜ ์•Š์•„์„œ Solution ๋ณด๋ฉด์„œ ํ•ด๊ฒฐํ–ˆ๋„ค์š”. ใ…Žใ…Ž

153. Find Minimum in Rotated Sorted Array

Complexities ๐Ÿ“ˆ

  • Time Complexity: $O(log n)$
  • Space Complexity: $O(1)$

Explanation ๐Ÿ“

์ตœ์†Œ ๊ฐ’์„ ๊ตฌํ•˜๋Š” ๊ฒƒ์ด๋‹ค๋ณด๋‹ˆ $O(n)$์œผ๋กœ ์ตœ์†Ÿ๊ฐ’์„ ๊ตฌํ•ด๋„ ๋˜์ง€๋งŒ, ์ด๋ถ„ํƒ์ƒ‰์„ ์‚ฌ์šฉํ•˜์—ฌ ์›ํ•˜๋Š” ์ตœ์†Ÿ๊ฐ’์„ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์„ ์ฐธ๊ณ ํ•˜์—ฌ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์œผ๋กœ $O(log n)$๋งŒํผ์˜ ์ตœ์ ํ™”๋ฅผ ํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

33. Search in Rotated Sorted Array

Complexities ๐Ÿ“ˆ

  • Time Complexity: $O(log n)$
  • Space Complexity: $O(1)$

Explanation ๐Ÿ“

์ด๋ถ„ํƒ์ƒ‰ ์ ‘๊ทผ์— ์ข€ ์–ด๋ ค์›€์„ ๊ฒช์–ด์„œ ํ’€์ด๋ฒ•์„ ๋ณด๊ณ  ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž..

Copy link
Contributor

@Invidam Invidam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋‚จ์€ ๋ฌธ์ œ๋“ค๋„ ํ™”์ดํŒ…..!! ๐Ÿ‘

@WhiteHyun WhiteHyun marked this pull request as ready for review June 10, 2024 04:55
@WhiteHyun WhiteHyun merged commit 6b99c02 into DaleStudy:main Jun 10, 2024
@WhiteHyun WhiteHyun deleted the whitehyun/week6 branch June 10, 2024 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

2 participants