Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1601b3f

Browse files
committed
Time: 42 ms (44.04%) | Memory: 18.5 MB (39.45%) - LeetSync
1 parent 8e00455 commit 1601b3f

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, val=0, next=None):
4+
# self.val = val
5+
# self.next = next
6+
class Solution:
7+
def oddEvenList(self, head: Optional[ListNode]) -> Optional[ListNode]:
8+
9+
if head:
10+
11+
head2 = head.next
12+
else:
13+
return head
14+
15+
16+
i1 = head
17+
if i1.next != None:
18+
i2 = i1.next.next
19+
20+
j1 = head2
21+
if j1:
22+
if j1.next != None:
23+
j2 = j1.next.next
24+
else:
25+
return head
26+
27+
while i2 != None:
28+
29+
i1.next = i2
30+
31+
if j1!= None:
32+
j1.next = j2
33+
34+
35+
if i2 != None and i2.next!=None:
36+
i2 = i2.next.next
37+
else:
38+
i2 = None
39+
40+
41+
if j2 != None and j2.next!=None:
42+
j2 = j2.next.next
43+
else:
44+
j2 = None
45+
46+
i1 = i1.next
47+
if j1 != None:
48+
j1 = j1.next
49+
i1.next = head2
50+
51+
return head

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /