Skip to content

Commit 15517ef

Browse files
committed
Solve 328 with python
1 parent f1f937b commit 15517ef

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
# Author: illuz <iilluzen[at]gmail.com>
4+
# File: AC_double_n.py
5+
# Create Date: 2016-02-23 19:16:07
6+
# Usage: AC_simulation_n.py
7+
# Descripton:
8+
9+
10+
# Definition for singly-linked list.
11+
class ListNode(object):
12+
def __init__(self, x):
13+
self.val = x
14+
self.next = None
15+
16+
class Solution(object):
17+
def oddEvenList(self, head):
18+
"""
19+
:type head: ListNode
20+
:rtype: ListNode
21+
"""
22+
if not head:
23+
return head
24+
evenhead = head.next
25+
odd, even = head, evenhead
26+
while even and even.next:
27+
odd.next = odd.next.next
28+
even.next = even.next.next
29+
odd, even = odd.next, even.next
30+
odd.next = evenhead
31+
return head

0 commit comments

Comments
 (0)