-
-
Notifications
You must be signed in to change notification settings - Fork 195
[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
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.
풀이와 코드가 정말 깔끔해서 많이 배우고 갑니다~! 이번 주도 고생 많으셨습니다 🍀
queue = deque([(0, 0)]) | ||
vis = set() | ||
|
||
while queue: |
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.
저는 처음에 unbounded knapsack 문제로 접근해서 DP로 풀었는데요, 이렇게 최단거리를 구하듯이 BFS로 푸는 것이 더 직관적인 것 같습니다!
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.
unbounded knapsack으로도 풀 수 있군요! 이 방법도 공부해 보겠습니다 ㅎㅎ
if board[y][x] != word[idx]: | ||
return False | ||
|
||
tmp, board[y][x] = board[y][x], '#' |
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.
이렇게 board에 inplace로 방문 표시를 하면 공간 복잡도 측면에서 최적화가 가능하네요!
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.
원래 있던 board만 사용하는거라 공간 복잡도 측면에서 최적화가 가능할 것 같아요!
|
||
def dfs(tree: Optional[TreeNode], depth: int): | ||
nonlocal result | ||
if tree == None: |
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.
예전에 파이썬에서 None
과 비교할 때 ==
를 쓰는 것과 is
를 쓰는 것의 차이점을 검색해본 적이 있는데요,
==
: 비교하는 객체의__eq__()
메서드 실행 (➡️ 메서드 오버라이드 시 side effect 발생 가능)is
:None
객체와의 reliable 한 비교 가능
이렇게 동작 방식이 달라서 is
를 이용해서 None
과 비교하는 것을 권장하는 것 같습니다! (물론 알고리즘 인터뷰와 같은 상황이나 대부분의 경우에는 괜찮다고 하네요)
예전에 얻었던 작은 조각 지식 공유드립니다...! 😄
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.
오오! 좋은 정보 감사합니다 python에 익숙하지 않아서 적응중인데 이런 작은 정보 하나하나가 소중하네요,, 감사합니다 ㅎㅎ
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!