链表-删除链表a/b处的节点

//删除链表a/b处的节点
public Node removeByBatio(Node head,int a,int b){
    if(a<1||a>b){
        return head;
    }
    int len=0;
    Node cur=head;
    while(cur!=null){
        len++
        cur=cur.next;
    }
    len=(int)Math.ceil(((double)(a*len))/(double)b);
    if(len==1){
        head=head.next;
    }
    if(len>1){
        cur=head;
        while(--len!=1){
            cur=cur.next;
        }
        cur.next=cur.next.next;
    }
    return head;
}

猜你喜欢

转载自blog.csdn.net/weixin_42146769/article/details/88388549