-
-
Notifications
You must be signed in to change notification settings - Fork 195
[hi-rachel] Week 06 Solutions #1418
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.
6주차도 수고 많으셨습니다. 알고리즘을 파이썬으로도 작성해주셔서 편하게 리뷰할 수 있었고, 전체적으로 읽기 편하고 깔끔한 답안이었던 것 같아요.
남은 스터디 기간도 파이팅입니다. :-)
valid-parentheses/hi-rachel.ts
Outdated
* TEST CASE: "]", "){", ")(){}" | ||
* | ||
* [원인] | ||
* if (stack.pop() !== parentheseMap[char]) return false; 비교시 |
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.
파이썬 풀이도 함께 적어주셔서 TS를 사용해본 적 없음에도 알고리즘을 잘 이해할 수 있었습니다.👍
valid-parentheses/hi-rachel.ts
Outdated
// if char in open_parenthese: | ||
// stack.append(char) | ||
// else: | ||
// if (not stack or stack.pop() != parentheseMap[char]): |
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.
파이썬에서는 스택에 pop하기 전 반드시 비어있는지 확인해주어야 한다는 걸 저도 이번 문제 풀면서 새롭게 알게 되었습니다.
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.
@river20s 두 가지 언어의 차이를 느낄 수 있었던 풀이였습니다.
""" | ||
|
||
# TC: O(N^2), SC: O(1) | ||
# 모든 경우의 수를 따져 가장 넓이가 크게 나오는 경우를 찾는 풀이 -> Time Limit Exceeded |
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.
파이썬은 특히나 TLE가 쉽게 나오는 것 같습니다. TS로 이런 로직을 구현하면 TLE가 나지는 않는지 궁금해집니다.
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.
@river20s 저는 파이썬에서 타입스크립트로 바꾼다고 시간, 공간 복잡도가 크게 바뀐 경우는 본 적이 없는 것 같습니다. 어떤 로직과 자료구조를 사용하는지가 중요하고 둘 다 인터프리터 언어이기 때문에 큰 차이는 없다고 생각합니다.
def addWord(self, word: str) -> None: | ||
node = self.root | ||
for ch in word: | ||
if ch not in node: # 글자가 node에 없으면 |
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.
@river20s 달레님 코드 해설을 보고 따라했습니다. 다시 한 번 복습도 해야겠네요 감사합니다!
node["$"] = True # 단어 끝 표시 | ||
|
||
|
||
# TC: O(26^W) => 최악의 경우 영어 알파벳 26개가 각 노드에서 다음 글자가 됨 * 글자수의 비례해서 호출 스택 깊어짐, SC: O(W) |
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.
26은 변하지 않는 상수이기 때문에 여기서 TC를 O(W)로 봐도 무방하지 않을까 생각합니다!
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.
@river20s 그럴 수 있겠네요! 최악의 경우 모든 알파벳의 경우가 나올 수 있다는 점을 기억하고 싶어 적었습니다 :)
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!