-
Notifications
You must be signed in to change notification settings - Fork 126
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
[Hyun] Week 2 Solution Explanation #47
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.
PRμ μ 리λ₯Ό λ무 μν΄ μ£Όμ μ μ λ λ¬Έμ νΈλλ° μ°Έκ³ ν΄μ λμμ΄ λ§μ΄ λμμ΅λλ€! Joma Tech μ΄λΆ μλ₯ μ νλ²μΈ μ€ μμλλ° ν ν¬ μ νλ²μκ΅°μ γ γ
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.
λλΆμ μ¬λ°λ Swfit μ½λ μ μ½μμ΅λλ€! π
|
||
final class LeetCode226 { | ||
func invertTree(_ node: TreeNode?) -> TreeNode? { | ||
guard let node else { return nil } |
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 μ« μ©λλ― γ γ
// νμ§λ§, κ° κ΄νΈμ μμ€ν€ κ°μ΄ 3 μ΄μ λλ κ²½μ°λ μλ‘ λ§μ§ μμ. | ||
// Swiftμμλ asciiValue νλ‘νΌν°μ νμ μ΄ `UInt8` μ΄κΈ° λλ¬Έμ μμκ° μμ΄μ κ°λ₯ν λΉκ΅! | ||
// `&-` λ μ€λ²νλ‘μ° μ°μ°μΌλ‘, λ§μ½ μ€λ²νλ‘μ°κ° λλ€λ©΄ 무μν¨. | ||
if character.asciiValue! &- stack.last!.asciiValue! > 2 { |
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.
무μ무μ ν©λλ€ γ γ
μ μ΄ λΆλΆμ κΆνμ΄ μμ΄μ μ κ° λ°λ‘ μ€μ ν΄λμμ΅λλ€ νν; ν° μλ―Έλ λ΄μ§ μμμ΄μ. |
γ γ λ³ κ±°λ μλκ³ μ. Priority μ€μ μ νλκΉ νλ‘μ νΈ λ³΄λμμ λ무 νμ΄λ³΄μ΄λλΌκ³ μ. νΌμ μ΄ μλλ‘ μ μ°λ νλλ μμ νμμ΅λλ€. π |
20. Valid Parentheses
Complexities π
Explanation π
&-
μ°μ° κ³Όμ κ° λ¬Έμμ΄μ μννμ¬ μ΄λ¦° κ΄νΈλ©΄ μ€νμ λ£κ³ , λ«ν κ΄νΈλ©΄ μλ§λ κ΄νΈμΈμ§ νμΈνκ³ μ§μ°λ μμ μΌλ‘ λ¬Έμ λ₯Ό ν΄κ²°νμ΅λλ€.
κ΄νΈκ° μλ§μμ§ νμΈνκΈ° μν΄ ASCII valueμ μ°¨μ΄λ₯Ό νμΈνμ΅λλ€.
κ·Έλμ λ«ν κ΄νΈλ₯Ό λ°κ²¬νμ κ²½μ° ASCIIκ°μ μ°¨μ΄λ₯Ό μ£Όμ΄ ν΄κ²°νμ΅λλ€.
overflowκ° λ°μν μΌλ €κ° μμ΄μ Swiftμμ μ 곡νλ μ€λ²νλ‘μ° μ°μ°μΈ
&
λ₯Ό μ΄μ©νμ΅λλ€.&-
λ₯Ό μ΄μ©νλ©΄ λΊμ μ νλ, μ€λ²νλ‘μ°λ₯Ό 무μν©λλ€.21. Merge Two Sorted Lists
Complexities π
Explanation π
μ²μμ λλ―Έ λ Έλ(dummy node)λ₯Ό μΆκ°νκ³ μ²« λ²μ§Έ λ Έλμ λ λ²μ§Έ λ Έλμ λΉκ΅λ₯Ό ν΅ν΄ ν¬μΈν°λ₯Ό λΆμ¬λκ°λ μμΌλ‘ ꡬννμ΅λλ€. μ΄ κ³Όμ μ λ 리μ€νΈ μ€ νλλΌλ λμ λλ¬ν λκΉμ§ λ°λ³΅ν©λλ€.
λ§μ§λ§μΌλ‘ μμ§ λ¨μμλ λ Έλλ€μ λ³ν©λ 리μ€νΈμ λμ μΆκ°νκ³ , λλ―Έ λ Έλμ λ€μ λ Έλλ₯Ό λ°ννμμ΅λλ€. λλ―Έλ Έλλ λ€μ ν¬μΈν°λ₯Ό λΆμ΄κΈ° μν μ¬μ μμ μ΄λκΉμ.
Tip
μ½λλ₯Ό λ³Ό λ μλ©΄ μ’μ μ
Swiftμ
??
μ°μ°μλNil-Collapsing
μ°μ°μλ‘, λ§μ½ μμ μλ κ°μ΄nil
μ΄λΌλ©΄??
μ°μ°μ λ€μ κ°μΌλ‘ μ²λ¦¬ν©λλ€.141. Linked List Cycle
Complexities π
Explanation π
Floyd's Tortoise and Hare
λ₯Ό μ¬μ©νμ΅λλ€. Joma Techμ If Programming Was An Animeμ λ³Έ κ² μκ°λλ λ¬Έμ μμ΅λλ€ πμ΄ μκ³ λ¦¬μ¦μ λ κ°μ ν¬μΈν°λ₯Ό νμ©νκ³ , νλλ νλμ λ Έλλ₯Ό, νλλ λ κ°μ λ Έλλ₯Ό μ΄λνμ¬ κ³μν΄μ μνν©λλ€. λ§μ½ λ ν¬μΈν°μ μμΉκ° λμΌν΄μ§λ€λ©΄, Cycleμ΄ μλ€λ λ»μ λλ€.
206. Reverse Linked List
Complexities π
Explanation π
μ¬κ·λ‘ νμμ΅λλ€. κΈ°μ‘΄ ListNodeμ μ°κ²°μ μ½κ°μ© μμ νμ¬ λ¬Έμ λ₯Ό ν΄κ²°νμ΅λλ€.
226. Invert Binary Tree
Complexities π
Explanation π
TreeNodeμ leftμ rightμ λ³κ²½ν΄μ£Όκ³ ,βΊοΈ
κ° leftμ rightλ₯Ό μ¬κ·λ‘ λλ € κ°μ μ²λ¦¬νμ΅λλ€.
μ΄λ²μλ μ¬κ·λ‘ νλ§ν λ¬Έμ λ€μ΄ λ§μλ€μ