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

[Leo] 2nd Week solutions #53

Merged
merged 1 commit into from
May 9, 2024
Merged

[Leo] 2nd Week solutions #53

merged 1 commit into from
May 9, 2024

Conversation

leokim0922
Copy link
Contributor

I do hate Linked List

@leokim0922 leokim0922 self-assigned this May 7, 2024
Comment on lines +10 to +14
while curr:
tmp = curr.next ## save next node
curr.next = prev ## reverse next pointer to the prev
prev = curr ## update prev pointer with curr, since it's reversed now
curr = tmp ## move on to the next saved node
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
while curr:
tmp = curr.next ## save next node
curr.next = prev ## reverse next pointer to the prev
prev = curr ## update prev pointer with curr, since it's reversed now
curr = tmp ## move on to the next saved node
while curr:
curr.next, prev, curr = prev, curr, curr.next

tmp 사용 없이 이렇게 하는 방법도 있을 것 같아요. ☺️

Copy link
Contributor Author

@leokim0922 leokim0922 May 8, 2024

Choose a reason for hiding this comment

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

감사합니다!! 포인터 문제들은 늘 할때마다 헷갈려서 tmp 해놓은거도 있고 안해놓은거도 있고 뒤죽박죽이네요 ㅎㅎ 좀 일관성있게 작성하도록 노력해보겠습니다 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

오 파이썬은 temp 없이 스왑이 되는군요...!


return root

## TC: O(n), SC: O(n), avg O(logn) if the given tree is balanced
Copy link
Contributor

Choose a reason for hiding this comment

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

훌륭한 복잡도 분석이네요! 💯

@DaleSeo DaleSeo merged commit 71d9c80 into DaleStudy:main May 9, 2024
1 check passed
@DaleSeo DaleSeo added this to the week2 milestone May 12, 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.

4 participants