-
Notifications
You must be signed in to change notification settings - Fork 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
[Leo] 2nd Week solutions #53
Conversation
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 사용 없이 이렇게 하는 방법도 있을 것 같아요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사합니다!! 포인터 문제들은 늘 할때마다 헷갈려서 tmp 해놓은거도 있고 안해놓은거도 있고 뒤죽박죽이네요 ㅎㅎ 좀 일관성있게 작성하도록 노력해보겠습니다 😄
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
훌륭한 복잡도 분석이네요! 💯
I do hate Linked List