Skip to content

Commit 165b468

Browse files
committed
Time: 3 ms (16.16%), Space: 19.4 MB (6.5%) - LeetHub
1 parent 17895a7 commit 165b468

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

0328-odd-even-linked-list/0328-odd-even-linked-list.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
# self.val = val
1414
# self.next = next
1515
class Solution:
16+
'''
17+
# Linked-list
18+
- TC is O(1), travarse once
19+
- SC is O(1), no additional structure
20+
'''
1621
def oddEvenList(self, head: Optional[ListNode]) -> Optional[ListNode]:
1722
if head is None:
1823
return None
@@ -25,8 +30,11 @@ def oddEvenList(self, head: Optional[ListNode]) -> Optional[ListNode]:
2530

2631
while even is not None and even.next is not None:
2732
odd.next = even.next
28-
odd = odd.next
29-
33+
odd = odd.next
34+
'''
35+
In this case, when each traverse step, \U0001f449 move the odd first to simplify the pointer jumping and etc. Like `even = even.next.next` or use addition temp variable.
36+
'''
37+
3038
even.next = odd.next
3139
even = even.next
3240

0 commit comments

Comments
 (0)