1ms java 111111111111


  • 0
    E

    public class Solution {
    public ListNode removeNthFromEnd(ListNode head, int n) {
    ListNode head1=head;
    ListNode del=null;
    //if(head.next==null) return head.next;
    while(head.next!=null){
    n--;
    if(del!=null) del=del.next;
    if(n==0) del=head1;
    head=head.next;
    }
    if(n==1) return head1.next;
    head=del;
    // if(del.next.next==null) head.next=null;
    // else
    head.next=del.next.next;
    return head1;
    }


Log in to reply
 

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