odd_even_list

 public class Solution
{
public ListNode OddEvenList(ListNode head)
{
if(head == null || head.next == null || head.next.next == null) return head; //考虑特殊情况,0、1、2个点,直接返回
ListNode res = head,a = head; //a遍历奇数点 res记录奇数最开始的点
ListNode bb=head.next,b = head.next; //b遍历偶数点 bb 记录偶数最开始的点
while (a.next != null && a.next.next !=null) {
a.next = a.next.next;
b.next = b.next.next;
a = a.next;
b = b.next;
}
if (a.next != null)
{
b.next = null;
}
a.next = bb;
return res;
}
}
上一篇:C#实现打印与打印预览功能


下一篇:Confluence 6 重构索引缓慢