Don't understand why MLE? Who can help!!!!


  • 0
    C
    public class Solution {
        public ListNode partition(ListNode head, int x) {
            ListNode dummy = new ListNode(0);
            dummy.next = head;
            ListNode p = dummy;
            ListNode q = p;
            ListNode tmp1 = null;
            while (q != null && q.next != null) {
                if (q.next.val < x) {
                    if (p != q) {
                        tmp1 = p.next;
                        p.next = q.next;
                        q.next = q.next.next;
                        p.next.next = tmp1;
                    }
                    p = p.next;
                    q = q.next;
                } else {
                    q = q.next;
                }
            }
            if (q != null && q.val < x) {
                tmp1 = p.next;
                p.next = q;
                p.next.next = tmp1;
            }
            return dummy.next;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.