Skip to content
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

[croucs] WEEK 2 #714

Merged
merged 3 commits into from
Dec 20, 2024
Merged

[croucs] WEEK 2 #714

merged 3 commits into from
Dec 20, 2024

Conversation

heypaprika
Copy link
Contributor

@heypaprika heypaprika commented Dec 16, 2024

답안 제출 문제

체크 리스트

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

@heypaprika heypaprika requested a review from a team as a code owner December 16, 2024 02:48
@github-actions github-actions bot added the py label Dec 16, 2024
Comment on lines +43 to +58
class Solution:
def buildTree(self, preorder: List[int], inorder: List[int]) -> Optional[TreeNode]:
if len(preorder) == 0:
return None
if len(preorder) == 1:
return TreeNode(preorder[0])
root = TreeNode(preorder[0])

split_idx = inorder.index(preorder[0])
left_inorder = inorder[:split_idx]
right_inorder = inorder[split_idx+1:]
left_preorder = preorder[1:len(left_inorder)+1]
right_preorder = preorder[len(left_inorder)+1:]
root.left = self.buildTree(left_preorder, left_inorder)
root.right = self.buildTree(right_preorder, right_inorder)
return root
Copy link
Contributor

Choose a reason for hiding this comment

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

inorder과 preorder의 관계를 사용하여 dfs 풀이도 참조하시면 문제 이해에 더 도움이 되시지 않을까 싶습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

인덱스만 가지고 할 수도 있었군요..! 참조해주셔서 감사합니다!

Copy link
Contributor

@TonyKim9401 TonyKim9401 left a comment

Choose a reason for hiding this comment

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

2주차 풀이도 고생 많으셨습니다!
시간, 공간 복잡도도 잘 정리해주셔서 이해하기 쉬었네요.
고생하셨습니다!

@heypaprika heypaprika merged commit 2007a35 into DaleStudy:main Dec 20, 2024
1 check passed
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