Skip to content

[sejineer] Week 04 solutions #1334

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
Apr 26, 2025
Merged

[sejineer] Week 04 solutions #1334

merged 5 commits into from
Apr 26, 2025

Conversation

sejineer
Copy link
Contributor

@sejineer sejineer commented Apr 20, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

Copy link
Contributor

@seungriyou seungriyou left a comment

Choose a reason for hiding this comment

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

풀이와 코드가 정말 깔끔해서 많이 배우고 갑니다~! 이번 주도 고생 많으셨습니다 🍀

queue = deque([(0, 0)])
vis = set()

while queue:
Copy link
Contributor

Choose a reason for hiding this comment

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

저는 처음에 unbounded knapsack 문제로 접근해서 DP로 풀었는데요, 이렇게 최단거리를 구하듯이 BFS로 푸는 것이 더 직관적인 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unbounded knapsack으로도 풀 수 있군요! 이 방법도 공부해 보겠습니다 ㅎㅎ

if board[y][x] != word[idx]:
return False

tmp, board[y][x] = board[y][x], '#'
Copy link
Contributor

Choose a reason for hiding this comment

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

이렇게 board에 inplace로 방문 표시를 하면 공간 복잡도 측면에서 최적화가 가능하네요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

원래 있던 board만 사용하는거라 공간 복잡도 측면에서 최적화가 가능할 것 같아요!


def dfs(tree: Optional[TreeNode], depth: int):
nonlocal result
if tree == None:
Copy link
Contributor

Choose a reason for hiding this comment

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

예전에 파이썬에서 None과 비교할 때 ==를 쓰는 것과 is를 쓰는 것의 차이점을 검색해본 적이 있는데요,

  • ==: 비교하는 객체의 __eq__() 메서드 실행 (➡️ 메서드 오버라이드 시 side effect 발생 가능)
  • is: None 객체와의 reliable 한 비교 가능

이렇게 동작 방식이 달라서 is를 이용해서 None과 비교하는 것을 권장하는 것 같습니다! (물론 알고리즘 인터뷰와 같은 상황이나 대부분의 경우에는 괜찮다고 하네요)

예전에 얻었던 작은 조각 지식 공유드립니다...! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오오! 좋은 정보 감사합니다 python에 익숙하지 않아서 적응중인데 이런 작은 정보 하나하나가 소중하네요,, 감사합니다 ㅎㅎ

@sejineer sejineer merged commit 45b5686 into DaleStudy:main Apr 26, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from Solving to Completed in 리트코드 스터디 4기 Apr 26, 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