-
-
Notifications
You must be signed in to change notification settings - Fork 195
[jinhyungrhee] WEEK 02 solutions #1220
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.
idea01
부터 시작해서 알고리즘의 최적화가 이루어지는 과정을 인상깊게 보았습니다.
2주차도 너무 고생하셨습니다 👍
* | ||
*/ | ||
|
||
public boolean isAnagram03(String s, String t) { |
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.
두 개의 해시맵을 통해서 값을 비교하는 것은 흥미롭게 본 것 같습니다!
하나의 해시맵을 사용하는 isAnagram04
과 두 개의 해시맵을 사용하는 isAnagram03
은 어떨 때 각각 이점을 갖고 있을지 궁금합니다 :)
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.
isAnagram03
이 한글자 한글자씩 비교하는 방식이라 좀 더 직관적이고 가독성이 높은 것 같습니다. 그리고 s, t 두 문자열에 대한 빈도수를 모두 저장하여 갖고 있다보니 디버깅에 유리합니다. 하지만 해시맵을 각각 만들어야 한다는 점에서 상대적으로 공간 효율은 떨어집니다.
반면 isAnagram04
은 다소 가독성은 떨어지지만, 공간 효율에서 이점이 있습니다!
// METHOD3 : DP (Bottom-Up) | ||
// time-complexity : O(N) | ||
// space-complexity : O(N) | ||
public int dp(int n, int[] memo) { |
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.
알고 계실 수도 있으시겠지만, 동일한 Bottom-up
방식으로 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.
참고해보겠습니다 감사합니다!
dfs(root); | ||
// iterativeDFS(root); | ||
|
||
if (orderedList.isEmpty()) return false; |
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.
orderedList
라는 List
를 선언해서 검증하는 방식도 좋은 것 같습니다!
저는 따로 배열이나 리스트를 선언하지 않고 트리 구조를 탐색하는 도중 조건에 맞지 않을 경우, true
혹은 false
를 반환하는 방식으로 해결하였는데,
jinhyungrhee 님이 선택하신 방식은 배열에 노드를 담아낼 수 있어 코드는 조금 길어지겠지만 데이터 확인이나 디버깅이 편할 것 같습니다 :)
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!