0ms faster than 100% | JAVA easy sol only Iteration no stacks
Please Upvote if it helped you.\n\n\npublic ListNode removeNthFromEnd(ListNode head, int n) {\n        int count = 0; // creating a counter variable to get the 
Please **Upvote** if it helped you.\n\n```\npublic ListNode removeNthFromEnd(ListNode head, int n) {\n        int count = 0; // creating a counter variable to get the number of Nodes\n        \n        ListNode list = head;  // here creating a Node that will point to the head Node, so the list is now pointing to the head Node\n        \n        while(list != null) {    // as list is pointing to head Node and I wanna reach to the end Node, \n                                // I will run a loop starting from head Node until the end of the list i.e. until the list becomes null\n            \n            list = list.next;   // this statement will make "list" point to the next Node ( like in i++, if i is 1 then it will become 2 )\n                                // before list ---> head..... now list ---> head.next ( for easy understanding )\n            count++;            // as we\'ll go forward, we\'ll keep on increasing our counter variable to know the size of the list\n        }\n        \n        int node = count - n;   // this is position of required Node from the start \n                                // if list.size() == 9 and we need to delete 2nd element from end\n                                // node = 9 (size) - 2 (end position)  == 7 (position from start)\n        \n        if( node == 0) {        // suppose in above example position from end is 9\n                                // means position from start ==> 9-9 = 0\n                                // we have to delete the first element that is head so we\'ll simply return head.next \n                                \n            return head.next;   // list that will pass the whole list except head because we wanna delete it so head.next \n                                // as mentioned earlier head.next will point to second Node head here\n\n        }\n        list = head;            // now if you remember, we have iterated through this list pointer to know the size, so it will be pointing to the \n                                // last Node, in this statement I made sure that it again will point to the head Node ( Now you can understand why \n                                // we created a seperate Node "list" and not used the head Node in the argument\n        \n        while(node-- > 1) {     // here I\'m simply running a loop till node becomes less than 1 (not 0 because we need to go the Node before the \n                                // Node we wanna delete ( like if we wanna delete 7th Node so we\'ll go to Node 6 ) you\'ll see why\n            list = list.next;   // now the list Node will point to the 6th Node if we wanna delete 7th, after this loop completes\n        }\n        list.next = list.next.next;     // simply understand it by the notations below\n                                        // current situation :-  list ----> Node (6th)\n                                        //                       list.next = 7th Node\n                                        //                       list.next.next = 8th Node ( null if not present )\n                                        //  so here\'s the basic logic  :- if we wanna remove 7th Node we\'ll just cut it\'s link from 6th Node \n                                        //  and we\'ll make our 8th Node as 7th by pointing 6th Node\'s next to the 8th Node so 6th ----> 8th \n                                        \n        return head;                    // we can\'t return "list" for reasons explained earlier beacaue currently list is pointing to 6th Node\n                                        // and we have to return the starting Node so we\'ll return head Node\n                                        // if you\'re wondering how? then let me make this also clear that "list" is not a copy of head, it\'s just pointing \n                                        // to head Node, so the changes made will also reflect in the head Node\n                                        // I hope I explained everything, so Please Upvote if you haven\'t already\n    }\n```
['Iterator', 'Java']