Skip to content

[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

Merged
merged 9 commits into from
Apr 12, 2025
Merged

Conversation

jinhyungrhee
Copy link
Contributor

@jinhyungrhee jinhyungrhee commented Apr 7, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@jinhyungrhee jinhyungrhee moved this from Solving to In Review in 리트코드 스터디 4기 Apr 11, 2025
Copy link
Contributor

@HoonDongKang HoonDongKang left a 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

두 개의 해시맵을 통해서 값을 비교하는 것은 흥미롭게 본 것 같습니다!

하나의 해시맵을 사용하는 isAnagram04과 두 개의 해시맵을 사용하는 isAnagram03은 어떨 때 각각 이점을 갖고 있을지 궁금합니다 :)

Copy link
Contributor Author

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

Choose a reason for hiding this comment

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

알고 계실 수도 있으시겠지만, 동일한 Bottom-up 방식으로 O(1)의 공간 복잡도를 갖는 방식이 존재합니다 😃
알고달레 참고 링크 남겨드립니다 :)

Copy link
Contributor Author

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

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 님이 선택하신 방식은 배열에 노드를 담아낼 수 있어 코드는 조금 길어지겠지만 데이터 확인이나 디버깅이 편할 것 같습니다 :)

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