Skip to content

[박종훈] 7주차 답안 제출 #126

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 1 commit into from
Jun 15, 2024

Conversation

@dev-jonghoonpark dev-jonghoonpark marked this pull request as ready for review June 9, 2024 17:13
Copy link
Member

Choose a reason for hiding this comment

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

보고 배우겠습니다. 🙇
저에게는 아직 어려운 풀이법이네요 하하

Copy link
Contributor Author

@dev-jonghoonpark dev-jonghoonpark Jun 10, 2024

Choose a reason for hiding this comment

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

포인터 방식은 저도 어려워서
한참 잡고있었네요 ㅎㅎ

공간 복잡도가 줄긴 하는데
직관적이지는 못하다고 생각됩니다 ㅎㅎ
(데이터가 엄청 많지 않은 이상 크게 차이도 없고, 오히려 손해일수도...)

Copy link
Member

Choose a reason for hiding this comment

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

우선 선형적으로 길이를 구한 뒤 다시 처음부터 시작하여 length - n - 1 까지를 구해 타겟팅된 노드를 제거하는 전략이군요. 제가 생각지 못한 풀이법이라 새롭네요 ㅎㅎ

Comment on lines +18 to +22
// left로 갈 때 max를 자신으로, right로 갈 때는 min을 자신으로
if (!(dfs(node.left, min, node.val)
&& dfs(node.right, node.val, max))) {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

TreeNode끼리 비교하지 않고 Int 값으로 비교한 게 인상적이네요 ✨

Copy link
Contributor

Choose a reason for hiding this comment

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

포인터 없이 이렇게 풀어도 되는군요.. 저도 포인터는 쓸때마다 직관적으로 그려지지가 않는데 너무 흔하게 쓰이는 테크닉이라 버릴수도 없고 고민입니다 참고하도록 하겠습니다!

list.add(current);
current = current.next;
}
list.add(current);
Copy link
Contributor

Choose a reason for hiding this comment

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

혹시 이 부분을 빼고 위에 while 조건을 current != null 만 하는 방법은 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

while (current != null) {
    list.add(current);
    current = current.next;
}

말씀해주신대로 이렇게 수정해도 잘 동작하네요...! : ) 좋을 것 같습니다...!

@dev-jonghoonpark dev-jonghoonpark merged commit e31a67e into DaleStudy:main Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants