0
0

More than 1 year has passed since last update.

Leetcode 328. Odd Even Linked List

Posted at

328. Odd Even Linked List

難易度

Medium

package com.leetcode.easy;

public class OddEvenLinkedList328 {
    public static void main(String[] args) {

    }

    public ListNode328 oddEvenList(ListNode328 head) {
        if (head == null) {
            return head;
        }
        ListNode328 odd = head;
        ListNode328 even = head.next;
        ListNode328 evenHead = even;

        while (even != null && odd != null) {
            even.next = even.next.next;
            odd.next = odd.next.next;
            even = even.next;
            odd = odd.next;
        }
        odd.next = evenHead;
        return head;
    }
}

class ListNode328 {
    int val;
    ListNode328 next;

    ListNode328() {
    }

    ListNode328(int val) {
        this.val = val;
    }

    ListNode328(int val, ListNode328 next) {
        this.val = val;
        this.next = next;
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0