Skip to content

[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

Merged
merged 6 commits into from
May 10, 2025
Merged

[hi-rachel] Week 06 Solutions #1418

merged 6 commits into from
May 10, 2025

Conversation

hi-rachel
Copy link
Contributor

@hi-rachel hi-rachel commented May 4, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@river20s river20s self-requested a review May 4, 2025 15:02
Copy link
Contributor

@river20s river20s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6주차도 수고 많으셨습니다. 알고리즘을 파이썬으로도 작성해주셔서 편하게 리뷰할 수 있었고, 전체적으로 읽기 편하고 깔끔한 답안이었던 것 같아요.
남은 스터디 기간도 파이팅입니다. :-)

* TEST CASE: "]", "){", ")(){}"
*
* [원인]
* if (stack.pop() !== parentheseMap[char]) return false; 비교시
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파이썬 풀이도 함께 적어주셔서 TS를 사용해본 적 없음에도 알고리즘을 잘 이해할 수 있었습니다.👍

// if char in open_parenthese:
// stack.append(char)
// else:
// if (not stack or stack.pop() != parentheseMap[char]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파이썬에서는 스택에 pop하기 전 반드시 비어있는지 확인해주어야 한다는 걸 저도 이번 문제 풀면서 새롭게 알게 되었습니다.

Copy link
Contributor Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파이썬은 특히나 TLE가 쉽게 나오는 것 같습니다. TS로 이런 로직을 구현하면 TLE가 나지는 않는지 궁금해집니다.

Copy link
Contributor Author

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에 없으면
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

트라이를 사용하신 것 같은데 메서드 안에 직접 구현하신 부분이 읽을 때 깔끔하게 느껴졌습니다.

Copy link
Contributor Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

26은 변하지 않는 상수이기 때문에 여기서 TC를 O(W)로 봐도 무방하지 않을까 생각합니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@river20s 그럴 수 있겠네요! 최악의 경우 모든 알파벳의 경우가 나올 수 있다는 점을 기억하고 싶어 적었습니다 :)

@hi-rachel hi-rachel moved this from Solving to In Review in 리트코드 스터디 4기 May 10, 2025
@hi-rachel hi-rachel merged commit 23bcea3 into DaleStudy:main May 10, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review 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