-
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
[thispath98] Week 6 #895
[thispath98] Week 6 #895
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.
아하핳... 저도 처음에 이렇게 풀었었는데, 문제에 숨은 의도를 좀 더 파악해 보는것도 괜찮을것 같아요!
if stack: | ||
return False | ||
else: | ||
return True |
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.
return 시 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.
5, 6주차 문제 풀이 고생 많으셨습니다.
문제 올리는 것에 관계 없이 꾸준히 풀어주시는 모습에 감사드리고 도움이 되셨으면 좋겠습니다.
절반 정도의 기간 동안 고생 많으셨고 남은 8주도 파이팅입니다!
stack = [] | ||
for ch in s: | ||
if ch in ["(", "{", "["]: | ||
stack.append(ch) | ||
elif ch in [")", "}", "]"]: | ||
if stack and ( | ||
(ch == ")" and stack[-1] == "(") | ||
or (ch == "}" and stack[-1] == "{") | ||
or (ch == "]" and stack[-1] == "[") | ||
): | ||
stack.pop() | ||
else: | ||
return False | ||
|
||
if stack: | ||
return False | ||
else: | ||
return True |
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.
코드가 직관적이라 이해하기 쉬웠습니다! 딕셔너리를 활용하여 코드를 조금 더 간결하게 개선할 수 있을 것 같습니다.
class Solution: | ||
def groupAnagrams(self, strs: List[str]) -> List[List[str]]: | ||
anagram_dict = defaultdict(list) | ||
for string in strs: | ||
anagram_dict[tuple(sorted(string))].append(string) | ||
|
||
answer = list(anagram_dict.values()) | ||
return answer |
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.
리뷰가 늦어져서 죄송합니다. 저는 if-else문을 활용해서 키가 존재하는지의 여부를 체크했는데, defaultdict(list)를 사용하면 예외처리를 더 간단하게 할 수 있다는 걸 알게 됐습니다! 이번 주도 고생하셨습니다!
답안 제출 문제
Week 5 문제들을 PR 하지 못해서 부득이하게 이번주에 포함시켰습니다.
Week 5
Week 6
체크 리스트
In Review
로 설정해주세요.