-
-
Notifications
You must be signed in to change notification settings - Fork 362
[yuseok89] WEEK 04 Solutions #2739
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
Changes from 30 commits
4836151
cdc00da
cc0a988
c894055
4e4e412
32cafb9
49ecb59
a6fcc33
38a1f67
8bd5a32
05685ed
cd23e34
120df1f
1d4ff54
23142a7
0cb14ca
9465142
8b4a01f
4b09054
da3aad9
5c4d5fb
03f3f1a
d8d5ea4
1f003e2
a022d10
b8248c4
51c1012
65431c0
e514ab2
194db1c
419dfc5
af586d8
e2f0e02
41107c5
37ecdd8
fc56573
350342d
0a99924
2f86595
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 두 리스트를 동시에 순회하며 더 작은 노드를 연결한다. 개선 제안: 현재 구현이 적절해 보입니다. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # TC: O(N) | ||
| # SC: O(1) | ||
| # Definition for singly-linked list. | ||
| # class ListNode: | ||
| # def __init__(self, val=0, next=None): | ||
| # self.val = val | ||
| # self.next = next | ||
| class Solution: | ||
| def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: | ||
|
|
||
| ret = ListNode() | ||
| cur = ret | ||
|
Comment on lines
+11
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ret은 무슨 약자일까요?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return value 약자로 썼는데, |
||
|
|
||
| while list1 and list2: | ||
| if list1.val < list2.val: | ||
| cur.next = list1 | ||
| list1 = list1.next | ||
| else: | ||
| cur.next = list2 | ||
| list2 = list2.next | ||
| cur = cur.next | ||
|
|
||
| while list1: | ||
| cur.next = list1 | ||
| list1 = list1.next | ||
| cur = cur.next | ||
|
|
||
| while list2: | ||
| cur.next = list2 | ||
| list2 = list2.next | ||
| cur = cur.next | ||
|
|
||
| return ret.next | ||
|
|
||
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.
이거 2개 비교하는 부분 끝나고 리스트 두개중에 한개 순회 다 끝난 상태에서는 나머지 남은 리스트는 그냥 뒤에 통째로 붙혀주는게 더 좋더라구요!
그니까 while 말구 단일 if문으로 처리가 가능해서 이게 훨씬 깔끔하고 좋은것 같았어요
파이썬의 or가 어떻게 단축평가를 하는지 고려하면 더욱 줄일수도 있구요!
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.
의견 감사합니다.
굳이 더 순회 할 필요 없었네요.
파이썬 or 도 좀 더 살펴보겠습니다.