-
-
Notifications
You must be signed in to change notification settings - Fork 248
[Hyun] Week 3 Solution Explanation #67
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฒ์จ ๋ค ํ์ผ์ จ๋ค๋..ใ ใ 1๋ฑ ์ถํ๋๋ฆฝ๋๋ค
PR ์ ๋ฆฌ๋ฅผ ๋๋ฌด ์ํ์๋ค์. ๋ค์์๋ ์ ๋ ์ฐธ๊ณ ํด์ ํด๋ณด๊ฒ ์ต๋๋ค! |
climbing-stairs/WhiteHyun.swift
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํด์ํ ์ด๋ธ์ ๊ฐ๋ค์ ์ ์ฅํ๋ฉด์ ์์๊ฐ ์๋ ์์ง๋ง, ํ์ฌ ๊ฐ์ ๊ณ์ฐํ๋๋ฐ ํ์ํ ๊ฐ์ ์ด์ ๊ฐ๊ณผ ๊ทธ ์ด์ ๊ฐ๋ง ํ์ํ๊ณ ๊ทธ ์ด์ ๊ฐ๋ค์ ์ธ๋ชจ ์์ด์ง๋๋ค. ์ด ์ ์ ์ดํดํ๊ณ ์ ๊ทผํ๋ฉด ๊ณต๊ฐ ๋ณต์ก๋๋ฅผ ์์ํญ์ผ๋ก ๋ง๋ค ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space Complexity๋ฅผ
์์ด๋์ด ๊ฐ์ฌํฉ๋๋ค! ๊ตฌํํด๋ณด๊ณ PR ๋ด์ฉ๋ ์์ ํ๊ฒ ์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๋ ์ฒ์์ Hyun๋๊ณผ ๊ฐ์ ๋ฐฉ์์ผ๋ก ํ์๋ค๊ฐ ๋ค๋ฅธ ๋ถ๋ค๊ป ํผ๋๋ฐฑ ๋ฐ๊ณ ๊ณ ์ณค์ต๋๋ค ใ ใ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฌ๊ธฐ ์ฐธ ๋ฐ๋์งํ ์ฅ๋ฉด์ด๊ตฐ์! ๐ค
*/ | ||
final class Solution { | ||
func canAttendMeetings(_ intervals: [Interval]) -> Bool { | ||
let sortedIntervals = intervals.sorted { lhs, rhs in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ค์ํํธ๋ ์ ๋ ฌํ๋ ค๋ฉด ์ฌ๋ฌ๊ฐ์ง๋ฅผ ์ง์ ๋ช ์ํด์ผ ํ๋๊ตฐ์ใ ใ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swift
์ธ์ด์ ํน์ง์ด๋ผ๊ธฐ ๋ณด๋ค๋ ๋ณ๋๋ก ๋ง๋ ๊ฐ์ฒด์ ์ ๋ ฌ ๊ธฐ์ค์ ์ปดํ์ผ๋ฌ๊ฐ ๋ชจ๋ฅด๊ธฐ ๋๋ฌธ์ ์ง์ ์๋ ค์ฃผ์ด์ผ ํฉ๋๋ค. ์ด๋ ๋ค๋ฅธ ์ธ์ด๋ ๋ง์ฐฌ๊ฐ์ง์์. ใ
ใ
ํ์ด์ฌ:
class Test:
a = 0
b = 0
array = [Test(), Test()]
array.sort() # โ TypeError: '<' not supported between instances of 'Test' and 'Test'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ง์ ๋ง๋์ ๊ฐ์ฒด๋ผ ๊ทธ๋ฌ๊ตฐ์. ์์ ์ฝ๋์ ์ดํด๊ฐ ๋ถ์กฑํ๋ค์ใ ใ ์ค๋ช ๊ฐ์ฌํฉ๋๋ค!
extension TreeNode: Equatable { | ||
public static func == (lhs: TreeNode, rhs: TreeNode) -> Bool { | ||
lhs.val == rhs.val && lhs.left == rhs.left && lhs.right == rhs.right | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฌธ์ ์ด์ ์ฃผ์ด์ง ํด๋์ค๋ฅผ ํ์ฅํ๋ค๋ ์ ์ ํ๊ตฐ์!
70. Climbing Stairs
Complexities ๐
O(n)Explanation ๐
DP๋ฅผ ์ด์ฉํ์ฌ ํ์ดํ์ต๋๋ค. ์ฒซ ์คํ ๋๋ ๋ ์คํ ์ผ๋ก ๊ฑด๋ ์ ์๋ค๋ ์ ์ ๊ณ ๋ คํ์ฌ n๋ฒ์งธ ๊ณ๋จ์ ์ค๋ฅด๊ธฐ๊น์งn - 1
๋ฒ์งธ ๊ณ๋จ๊ณผn - 2
๋ฒ์งธ ๊ณ๋จ์ ๊ฐ๋ ๋ฐฉ๋ฒ์ ๋ํ์ฌ ๊ตฌํํ์ต๋๋ค.@SamTheKorean ๋์ ์์ด๋์ด๋ก n ๋ฒ์งธ ๊ณ๋จ์ ์ค๋ฅด๊ธฐ ์ํด n-1๋ฒ์งธ์ ํ์์ n-2๋ฒ์งธ์ ํ์๋ง ํ์ํ๋ฏ๋ก, n๋งํผ์ ๊ณต๊ฐ์ ์ ๋ถ ํ ๋นํ ํ์ ์์ด 1๋ถํฐ n๊น์ง ์ฐจ๊ทผ์ฐจ๊ทผ ๊ฐ์ ์ ๋ฐ์ดํธํ์ต๋๋ค.
100. Same Tree
Complexities ๐
Explanation ๐
Swift์๋
Equatable
์ด๋ผ๋protocol(=interface)
๊ฐ ์๋๋ฐ์. ์ด protocol์ ์ค์ํ๋ ๊ฐ์ฒด๋ ์๋ก๋ฅผ ๋น๊ตํ ๋==
๋ฅผ ์ฌ์ฉํ ์ ์๊ฒ ๋ฉ๋๋ค.๊ทธ๋์ ์ ๋ ์๋์ ๊ฐ์ด ๊ตฌํํ์ฌ recursiveํ๊ฒ ๋์ํ๋๋ก ํ์ต๋๋ค.
104. Maximum Depth of Binary Tree
Complexities ๐
Explanation ๐
์ผ์ชฝ ์์ ๋ ธ๋์ ์ค๋ฅธ์ชฝ ์์๋ ธ๋์ depth๊ฐ ๋ค๋ฅผ ์๋ ์๊ธฐ์ ๊ฐ ์์ ๋ ธ๋์๊ฒ
maxDepth
๋ฅผ ํธ์ถํ์ฌ ๊น์ด๋ฅผ ๊ตฌํ ํ ์ต๋๊ฐ์ ๊ฐ์ง๊ณ+1
ํ์ฌ ๋ฆฌํดํฉ๋๋ค.์ฌ๊ท๋ก ๊ตฌํํ์ต๋๋ค.
252. Meeting Rooms
Complexities ๐
Explanation ๐
๊ฐ ์๊ฐ๋๊ฐ ๊ฒน์น์ง ์๊ธฐ ์ํด์๋ ๋๋๋ ์๊ฐ๊ณผ ์์ํ๋ ์๊ฐ ์ฌ์ด์ ๊ฐญ์ด 0์ด์ ์กด์ฌํด์ผํฉ๋๋ค. ์๋ก ๊ฒน์ณ์๋ ์ ๋ฉ๋๋ค.
๋ฐ๋ผ์ Interval ์์ ์๊ฐ์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ ํ ๊ธฐ์ค ์์์ start ์๊ฐ๊ณผ ์ด์ ์์์ end ์๊ฐ์ด ๊ฒน์น๋์ง๋ฅผ ํ์ธํ์ต๋๋ค.
572. Subtree of Another Tree
Complexities ๐
Explanation ๐
100. Same Tree
์์ ํ์๋ ์ฝ๋๋ฅผ ์ด์ฉํ์ฌ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค.node๊ฐ subTree์ ๋์ผํ์ง๋ฅผ ๋ณธ ๋ค,
์๋๋ผ๋ฉด node์ ์ผ์ชฝ์์๋ ธ๋๋ ์ค๋ฅธ์ชฝ ์์๋ ธ๋์ subTree๋ฅผ ๋น๊ตํ์์ต๋๋ค.
์ฌ๊ท๋ก ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค.