-
-
Notifications
You must be signed in to change notification settings - Fork 195
[saysimple] 2주차 문제 풀이입니다. #66
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
Conversation
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.
pos를 실제로 추가하셔서 풀이를 하셨네요! 몇 가지 궁금한게 있습니다.
- 첫번째 if-statement 이 베이스 케이스를 필터하는거라면 리턴벨류를 boolean으로 하는게 더 맞지 않을까 생각해봅니다!
- SC 부분에 대한 의문이 있습니다. pos 파라미터를 따로 지정해주셨기 때문에 각 노드에 pos가 추가되면 O(n)이 되는게 아닌가 생각합니다..!
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.
-
맞습니다. Return False를 해주는 것이 타입에 맞습니다. 저렇게 작성한 이유는 제 경험에 한해서지만 현업 기준으로 객체가 없다는 False보단 None으로 처리하는 경우가 많고(객체가 할당되지 않았다=None이다, 파이썬 index같은 함수들에서 False가 아닌 -1이나 None을 리턴하는 이유) 파이썬의 if문에서 None은 False에 포함되기 때문에 사용하였습니다. 감사합니다!
-
O(n)이 시간복잡도 기준이라면 O(n)이 맞습니다. 공간 복잡도라면 해당 문제에서 원래 주어졌던 O(1)개의 객체에 변수가 추가된 것이기 때문에 O(1 + 1) = O(1) 이어서 O(1)이라 작성하였습니다. O(n)으로 보이신다면 원래 O(n)인 것을 제가 O(1)로 잘못 작성한게 아닐까 싶어요.
list1, list2 = list1.next, list2.next | ||
print(head) | ||
|
||
if list1: |
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.
여기서 부터는 반복문을 거치지 않고
냠은 부분을 전부 한번에 연결시키면 좋지 않을까 싶습니다
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.
그게 훨씬 좋아 보여요. 감사합니다!
Python 에서는 중간값 없이 swap이 가능하더라구요...! |
맞습니다. 간만에 링크드리스트를 푸니 C를 생각하며 풀어버렸네요 ㅋㅋㅌ. CPython 기준으로 시간복잡도도 손해를 봤군요. 비몽사몽.. |
이직 면접이 드뎌 다 끝나서 부랴부랴 제출합니다 ㅠㅠ
다음주 부터는 여유롭지 않을까... 라는 헛된 기대를 하는 중입니다. ㅋㅋ