LeetCode-328

Links:https://leetcode.com/problems/odd-even-linked-list/

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 1->2->3->4->5->NULL,
return 1->3->5->2->4->NULL.

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 …

解析:一次遍历即可,注意指针的操作和空指针。

 

【LeetCode】328. Odd Even Linked List
Tagged on:
0 0 投票数
Article Rating
订阅评论
提醒

4 评论
最新
最旧 最多投票
内联反馈
查看所有评论

哦?就是宜昌城区的?我也是宜昌的

博主是宜昌的人吗?宜昌哪个县的?