7 lines one pass java solution


  • 0
    S
    public class Solution {
        public ListNode removeNthFromEnd(ListNode head, int n) {
            ListNode rmv = head;
            ListNode tmp = head;
            int i = 0;
            while (i++ <n) if ((tmp = tmp.next) == null) return head.next;
            while ((tmp = tmp.next) != null) rmv = rmv.next;
            rmv.next = rmv.next.next;
            return head;
        }
    }

Log in to reply
 

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