天天看點

328. Odd Even Linked List——多利用fake_head

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.

You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity.

Example:

Given <code>1-&gt;2-&gt;3-&gt;4-&gt;5-&gt;NULL</code>,

return <code>1-&gt;3-&gt;5-&gt;2-&gt;4-&gt;NULL</code>.

Note:

The relative order inside both the even and odd groups should remain as it was in the input. 

The first node is considered odd, the second node even and so on ...

<a></a>

本文轉自張昺華-sky部落格園部落格,原文連結:http://www.cnblogs.com/bonelee/p/6243033.html,如需轉載請自行聯系原作者

繼續閱讀