Rust | 0ms Faster than 100% | Recursive solution with backtracking | No cloning
I want to make a shout out to the online booklet Learn Rust With Entirely Too Many Linked Lists -- it\'s a good way to learn how to use Rust\'s built-in tools t
I want to make a shout out to the online booklet [Learn Rust With Entirely Too Many Linked Lists](https://rust-unofficial.github.io/too-many-lists/) -- it\'s a good way to learn how to use Rust\'s built-in tools to massage code to satisfy the borrow chcker. It provides a nice exlaination for using `mem::replace`, when to use it, and `Option\'s` helpful `take()` function.\n\n\n```\nimpl Solution {\n    pub fn remove_nth_from_end(head: Option<Box<ListNode>>, n: i32) -> Option<Box<ListNode>> {\n        remove_nth_from_end_recr(head, n).0\n    }\n}\n    \nfn remove_nth_from_end_recr(head: Option<Box<ListNode>>, n: i32) -> (Option<Box<ListNode>>, usize) {\n    match head {\n        None => (None, 1),\n        Some(mut node) => {\n            let (prev, num) = remove_nth_from_end_recr(node.next.take(), n);\n            if n == num as i32 {\n                (prev, num+1)\n            } else {\n                node.next = prev;\n                (Some(node), num+1)\n            }\n        }\n    }\n}\n```\n\n\n```\nRuntime: 0 ms, faster than 100.00% of Rust online submissions for Remove Nth Node From End of List.\nMemory Usage: 2.1 MB, less than 37.35% of Rust online submissions for Remove Nth Node From End of List.\n```\n
['Rust']