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

[moonhyeok] Week10 #1015

Merged
merged 4 commits into from
Feb 15, 2025
Merged

[moonhyeok] Week10 #1015

merged 4 commits into from
Feb 15, 2025

Conversation

mike2ox
Copy link
Contributor

@mike2ox mike2ox commented Feb 10, 2025

답안 제출 문제

체크 리스트

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

@mike2ox mike2ox requested a review from a team as a code owner February 10, 2025 13:35
@github-actions github-actions bot added the ts label Feb 10, 2025
@mike2ox mike2ox requested a review from ekgns33 February 10, 2025 13:36
* Source: https://leetcode.com/problems/invert-binary-tree/
* 풀이방법: 재귀를 이용하여 트리를 뒤집음
*
* 시간복잡도: O(n) - n은 트리의 노드 수
Copy link
Contributor

Choose a reason for hiding this comment

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

재귀를 통해 풀어주셨군요! 👍 코드에서는 TreeNode를 새로 만들어서 return하는데 in-place로 구현할 수도 있을것같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

감사합니다. in-place로 바로 결과를 보낼 수 있는걸 잊었네요 ㅎㅎ

Copy link
Contributor

@HC-kang HC-kang left a comment

Choose a reason for hiding this comment

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

@mike2ox 님, 이번주도 고생 많으셨습니다~
벌써 2/3을 마치셨네요! 이제 남은 5주도 지금까지 하신만큼 꼭! 더 많은 것을 얻어가실 수 있으시면 좋겠습니다!

@@ -0,0 +1,21 @@
/**
* Source: https://leetcode.com/problems/jump-game/
* 풀이방법: 그리디로 접근
Copy link
Contributor

Choose a reason for hiding this comment

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

오.. 역으로 도착점을 당겨오는 풀이는 아이디어가 정말 새롭네요!

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로 그냥 해봤는데 시간오버떠서 뭔가 이미 도착했다는 전제하에 역으로 출발점을 찾는 식으로 하니까 해결됐습니다 ㅎㅎ..
PS할 때마다 이건 어떤 풀이법이 좋은지 찾는게 참 헷갈리네요

let head = null;
let tail = null;

for (let i = 0; i < sorted.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

순회 내에서 분기를 타는것보다는, 순회에 들어가기 전에 초기화를 해주는 방향은 어땠을까요?
내부 분기의 복잡도도 제거하고 매 순회마다 분기를 확인하는 연산도 줄일 수 있을 것 같아서 의견 드려요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

처음에 변수 선언과 동시에 초기화를 해줬었는데 순회 내부 로직이 안떠올라서 더 고민안하고 내버렸는데 리팩토링 한번 해보겠습니다 :)

let left = 0;
let right = nums.length - 1;

while (left <= right) {
Copy link
Contributor

Choose a reason for hiding this comment

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

중요하지 않은 내용입니다!

while문 내부의 코드가 흐름상 분명 불필요한 사족 없이 잘 짜여진 코드인데,
개인적으로 저는 묘하게 답답하고 읽기 힘든 느낌이 들어요.

분기문을 한줄로 간단하게 쓰신것도 좋지만, 약간의 구분감을 주시는것도 읽는 사람들에게 도움이 되지 않을까 싶어요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

너무 간단해서 중괄호를 제거했는데 그게 오히려 독이 됐군요. 가독성 부분을 더 신경써보겠습니다 :)

@mike2ox
Copy link
Contributor Author

mike2ox commented Feb 15, 2025

@mike2ox 님, 이번주도 고생 많으셨습니다~ 벌써 2/3을 마치셨네요! 이제 남은 5주도 지금까지 하신만큼 꼭! 더 많은 것을 얻어가실 수 있으시면 좋겠습니다!

감사합니다! 리뷰하신 부분 고려해서 PS풀 때 신경쓰겠습니다 :)

@mike2ox mike2ox merged commit d2782d4 into DaleStudy:main Feb 15, 2025
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.

3 participants