-
-
Notifications
You must be signed in to change notification settings - Fork 195
[EGON] Week 5 Solutions #456
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.
금주 수고많으셨습니다 👍
""" | ||
def solveWithStack(self, prices: List[int]) -> int: | ||
max_profit = 0 | ||
stack = [] |
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밖에 산정이 안될텐데 스택을 선택한 이유가 궁금합니다.
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.
말씀하신 것처럼 스택을 썼음을 명시하려고 사용했습니다. 그냥 정수형 변수 하나를 사용하면 이 문제는 상관없겠지만, 문제를 풀며 생각한 사고 방식을 위해 스택을 썼습니다. 예를 들어 n개의 주식 혹은 다른 조건이 붙어도 스택을 사용하는 방식이 유효할 것이라 생각해서 사용했습니다.
anagram_dict = {} | ||
for string in strs: | ||
key = ''.join(sorted(string)) | ||
anagram_dict[key] = anagram_dict.get(key, []) + [string] |
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.
파이썬에서 기존배열에 다른 배열을 합치려면 이렇게 표현하는군요 👍
def solveWithHashableKey(self, strs: List[str]) -> List[List[str]]: | ||
anagram_dict = {} | ||
for string in strs: | ||
key = ''.join(sorted(string)) |
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.
시간복잡도를 O(L * log L) * O(L) 이라고 해주셨는데요
제가 파이썬을 잘몰라서 잠깐 찾아본 얕은 지식으로는 sorted와 join은 독립된 연산으로 동작하는거 같아 질문드려요
저는 해당 코드의 시간복잡도가 O(L * log L)라고 생각하는데 EGON님은 어떻게 생각하시나요??
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.
길이가 L인 문자열에 대한 sorted에서 O(L * Log L), 정렬된 길이가 L인 배열을 하나의 문자열로 만드는데 O(L)이니 O(L * Log L) * O(L)이 맞는 것 같습니다
죄송합니다 다음부터 더 신경쓰도록 하겠습니다 수정해주셔서 감사합니다. |
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.