-
-
Notifications
You must be signed in to change notification settings - Fork 195
[river20s] WEEK 06 solutions #1419
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
- 스택 기반으로 괄호 유효 검사 문제 해결 (LeetCode 20, DaleStudy#222) - `Stack` 클래스와 내부 헬퍼 메서드로 알고리즘 작성 - 여는 괄호는 push, 닫는 괄호는 pop하여 매칭 여부를 확인하는 식으로 유효성을 검사함
- LeetCode 11에 대한 답안을 투 포인터를 사용해 구현 - left, right 포인터를 사용하여 컨테이너 넓이들을 계산하고 최댓값을 찾는 방식 - 더 낮은 높이 포인터를 이동하면서 최댓값을 구함 - TC: O(n), SC: O(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.
이번 한 주도 고생 많으셨습니다! 다음주도 화이팅입니다 😆
left = 0 # 왼쪽(시작) 포인터 | ||
right = n - 1 # 오른쪽(끝) 포인터 | ||
max_area = 0 | ||
|
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 char in self._closing_brackets | ||
|
||
def _is_match(self, open_bracket: str, close_bracket: str) -> bool: | ||
return self._matching_map.get(close_bracket) == open_bracket |
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.
코드가 체계적이고 객체지향적인 방식으로 잘 작성하신것 같아요. Stack 클래스를 직접 구현하고, Solution 클래스에서 이를 활용한 점이 인상적입니다. 👍
# 스택을 활용해 괄호 유효 검사 | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
def __init__(self): |
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.
Solution 클래스의 __init__
메서드에서 정의한 괄호 맵핑은 클래스 변수로 선언해도 좋을 것 같습니다.
return char in self._closing_brackets | ||
|
||
def _is_match(self, open_bracket: str, close_bracket: str) -> bool: | ||
return self._matching_map.get(close_bracket) == open_bracket |
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.
_is_match
메서드에서 get 메서드를 사용했는데, 이미 _is_closing
에서 유효한 괄호임을 확인했다면 직접 접근해도 안전할 것 같습니다. 😀
leetcode 211. Design Add and Search Words Data Structure
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!