My Javascript code can be passed locally, but not accepted


  • 0
    Y
    var oddEvenList = function (head) {
        if (!head) return null
        let odd = new ListNode(0)
        let even = new ListNode(0)
        //两个链表的头指针
        let oddHead = odd
        let evenHead = even
        let first = head.val
        while (head) {
            if (head.val % 2 !== 0) {
                odd.next = head
                odd = odd.next
            } else {
                even.next = head
                even = even.next
            }
            head = head.next
        }   
        //第一个节点值是奇数
        if (first % 2 !== 0) {
            even.next = null
            odd.next = evenHead.next
            return oddHead.next
        } else {
            odd.next = null
            even.next = oddHead.next
            return evenHead.next
        }
    };
    

    the case [2,1,4,3,6,5,7,8] is wrong but it can be passed locally .


Log in to reply
 

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