bm12 bm13

在这里插入图片描述在这里插入图片描述
在这里插入图片描述在这里插入图片描述
在这里插入图片描述在这里插入图片描述ok 边界头划分错了
在这里插入图片描述在这里插入图片描述在这里插入代码片

import java.util.*;

/*
 * public class ListNode {
 *   int val;
 *   ListNode next = null;
 * }
 */

public class Solution {
    /**
     * 
     * @param head ListNode类 the head node
     * @return ListNode类
     */
    public ListNode merge(ListNode phead1,ListNode phead2){
        if(phead1==null){
            return phead2;
        }
        if(phead2==null){
            return phead1;
        }
        ListNode head=new ListNode(0);
        ListNode cur=head;
        while(phead1!=null&&phead2!=null)
        {if(phead1.val<=phead2.val){
            cur.next=phead1;
            phead1=phead1.next;//phead1 定位后一 当前1链表
        }else{
            cur.next=phead2;
            phead2=phead2.next;//phead2 为了下次连接 定位到下个比较节点 类似1
        }
            cur=cur.next;//cur定位到新链表 此次循环内定位 新加节点 以便下次连接
        }
        if(phead1!=null){
            cur.next=phead1;
           // cur=cur.next;//没定位 之前 晕 不定位的话 好像也行 看眼答案
        }
      else
      {     cur.next=phead2;
        }
        return head.next;
        }
    public ListNode sortInList (ListNode head) {
        // write code here
   if(head==null||head.next==null){
       return head;
   }
        ListNode fast=head.next.next;
        ListNode slow=head.next;
        ListNode prev=head;
        while(fast!=null&&fast.next!=null){
            fast=fast.next.next;
            slow=slow.next;
            prev=prev.next;
        }
        prev.next=null;
        return merge(sortInList(head),sortInList(slow));
    }
}

在这里插入图片描述

在这里插入图片描述在这里插入图片描述注意 定义数组下标 应该用int 而不是用节点定义
在这里插入图片描述看了一眼
在这里插入图片描述在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值