We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4daba4c commit e4426a4Copy full SHA for e4426a4
src/com/fghpdf/OddEvenLinkedList/Solution.java
@@ -0,0 +1,30 @@
1
+package OddEvenLinkedList;
2
+
3
+import com.fghpdf.ListNode;
4
5
+/**
6
+ * @author fghpdf
7
+ * @date 2020/01/01
8
+ * @link https://leetcode.com/problems/odd-even-linked-list
9
+ * the problem donnot care the value in node, it just want to group odd even nodes by number.
10
+ * so it must first node is odd, second is even.
11
+ **/
12
+public class Solution {
13
+ public ListNode oddEvenList(ListNode head) {
14
+ if (head != null) {
15
16
+ ListNode odd = head;
17
+ ListNode even = head.next;
18
+ ListNode evenHead = even;
19
20
+ while (even != null && even.next != null) {
21
+ odd.next = odd.next.next;
22
+ even.next = even.next.next;
23
+ odd = odd.next;
24
+ even = even.next;
25
+ }
26
+ odd.next = evenHead;
27
28
+ return head;
29
30
+}
0 commit comments