Skip to content

[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

Merged
merged 5 commits into from
May 10, 2025
Merged

[river20s] WEEK 06 solutions #1419

merged 5 commits into from
May 10, 2025

Conversation

river20s
Copy link
Contributor

@river20s river20s commented May 4, 2025

답안 제출 문제

작성자 체크 리스트

  • 우측 메뉴에서 PR을 Projects에 추가해주세요.
  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

- 스택 기반으로 괄호 유효 검사 문제 해결 (LeetCode 20, DaleStudy#222)
- `Stack` 클래스와 내부 헬퍼 메서드로 알고리즘 작성
- 여는 괄호는 push, 닫는 괄호는 pop하여 매칭 여부를 확인하는 식으로 유효성을 검사함
@clara-shin clara-shin self-requested a review May 4, 2025 16:12
- LeetCode 11에 대한 답안을 투 포인터를 사용해 구현
- left, right 포인터를 사용하여 컨테이너 넓이들을 계산하고 최댓값을 찾는 방식
- 더 낮은 높이 포인터를 이동하면서 최댓값을 구함
- TC: O(n), SC: O(1)
Copy link
Contributor

@clara-shin clara-shin left a 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

Copy link
Contributor

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
Copy link
Contributor

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):
Copy link
Contributor

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
Copy link
Contributor

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에서 유효한 괄호임을 확인했다면 직접 접근해도 안전할 것 같습니다. 😀

river20s added 2 commits May 10, 2025 00:39
leetcode 211. Design Add and Search Words Data Structure
@river20s river20s merged commit 573d35b into DaleStudy:main May 10, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from Solving to Completed in 리트코드 스터디 4기 May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

2 participants