# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def oddEvenList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if head:
odd_tail=head
even_tail=head.next
while even_tail and even_tail.next:
temp=odd_tail.next
odd_tail.next=even_tail.next
even_tail.next=odd_tail.next.next
odd_tail.next.next=temp
odd_tail=odd_tail.next
even_tail=even_tail.next
return head
328. Odd Even Linked Lis
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- Given a singly linked list, group all odd nodes together ...
- Given a singly linked list, group all odd nodes together ...
- 将一个链表的奇数位结点链接成一个链表,偶数位结点链接成一个链表,然后将两个链表合并,奇数链表在前。 代码:
- Given a singly linked list, group all odd nodes together ...