题解 | #链表的奇偶重排#

链表的奇偶重排

http://www.nowcoder.com/practice/02bf49ea45cd486daa031614f9bd6fc3

 * function ListNode(x){
 *   this.val = x;
 *   this.next = null;
 * }
 */
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param head ListNode类 
 * @return ListNode类
 */
function oddEvenList( head ) {
    // write code here
    if(!head)    return head
    let cur = head,res1 = head.next,res2 = res1
    while(res2 && res2.next){
        cur.next = res2.next
        cur = cur.next
        res2.next = cur.next
        res2 = res2.next
    }
    cur.next = res1
    return head
}
module.exports = {
    oddEvenList : oddEvenList
};

alt

全部评论

相关推荐

点赞 评论 收藏
分享
03-16 13:56
湖南大学 C++
牛客872108596号:到现在没消息是挂了吗查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务