Skip to content

[hsskey] Week 02 Solutions #1231

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

[hsskey] Week 02 Solutions #1231

merged 6 commits into from
Apr 12, 2025

Conversation

hsskey
Copy link
Member

@hsskey hsskey commented Apr 7, 2025

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@YoungSeok-Choi YoungSeok-Choi self-requested a review April 10, 2025 00:15
@hsskey hsskey moved this from Solving to In Review in 리트코드 스터디 4기 Apr 11, 2025
Copy link
Contributor

@YoungSeok-Choi YoungSeok-Choi left a comment

Choose a reason for hiding this comment

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

이번주도 문제풀이하시느라 고생 많으셨습니다!
다음주도 화이팅입니다!

return false
}

return dfs(node.left, left, node.val) && dfs(node.right, node.val, right)
Copy link
Contributor

@YoungSeok-Choi YoungSeok-Choi Apr 12, 2025

Choose a reason for hiding this comment

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

안녕하세요! 좋은 주말입니다.

요 알고리즘 시간복잡도는 O(logN) 으로 생각이 되는데,
제 계산이 맞을까요??

아니라면 얼마나 되는지 궁금합니다!

Copy link
Member Author

Choose a reason for hiding this comment

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

안녕하세요 @YoungSeok-Choi

해당 풀이는 O(logN)이 아닌 O(n) 풀이입니다.
이 문제를 일반적인 이진탐색인 O(logN)으로 보일 수 있으나, 이 문제는 탐색 구현이 아니라
문제의 요구사항은 트리 전체를 확인하는 검증과정이라고 볼 수 있습니다.

풀이 중 조건문을 통과한 코드들은 마지막 return문에서 재귀적으로 동작하게되는데,
이를 시각화해서 보면 왼쪽과 오른쪽으로 코드가 마치 배열을 선형적으로 순회하듯이 거치는것을 확인할 수 있습니다.

따라서 해당 풀이는 O(n)풀이가 됩니다.

...
...
return dfs(node.left, left, node.val) && dfs(node.right, node.val, right)

@hsskey hsskey merged commit 9267bd9 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