100 % Faster🔥🔥 JAVA CODE || YOU WILL NOT GET THIS MUCH EASY CODE😎✌️
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->O(1)\n![Screenshot 2023-03-15 185755.png](https://assets.leetcode.com/users/images/7db3581c-70aa-44f5-a6ad-bbc9a83cd0c9_1679056324.048882.png)\n\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode() {}\n *     ListNode(int val) { this.val = val; }\n *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n    public ListNode removeNthFromEnd(ListNode head, int n) {\n\n        // Create a temporary node and a counter to find the length of the linked list\n        ListNode temp = head;\n        int count = 0;\n\n        // Traverse the linked list and count the number of nodes\n        while (temp != null) {\n            count++;\n            temp = temp.next;\n        }\n\n        // Calculate the index of the node to be removed from the beginning of the list\n        int len = count - n;\n\n        // If the first node needs to be removed, update the head and return\n        if (len == 0) {\n            head = head.next;\n        } \n        else {\n             // Traverse the list until the node before the one to be removed\n            ListNode prev = head;\n            while (len - 1 != 0) {\n                prev = prev.next;\n                len--;\n            }\n        // Remove the node by updating the previous node\'s next pointer\n        prev.next = prev.next.next;\n        }\n\n    // Return the head node of the modified list\n    return head;\n    }\n}\n```
['Linked List', 'Java']