Odd Even Linked List LeetCode solution in Java
1class Solution {2public ListNode oddEvenList(ListNode head) {3if (head == null) {4return head;5}6ListNode result = head, evenHalf = new ListNode(0), evenHalfPtr = evenHalf;7for (; head.next != null; head = head.next) {8evenHalfPtr = evenHalfPtr.next = head.next;9head.next = head.next.next;10evenHalfPtr.next = null;11if (head.next == null) {12break;13}14}15head.next = evenHalf.next;16return result;17}18}