LeetCode's challenge of June 2, 2020 (#237) asks us to delete a Node from a LinkedList. The tricky part is that we only have access to the Node itself, not to the head or parent Node.
Node 5, as part of the LinkedList
(4->5->1->9), we're expected to return
(4->1->9) with the Node 5 cut out of the list.
Admittedly, the question is rather confusing. One would expect access to the head and a target value to find and cut out. However, that's not the case. So, we need to dig deeper into the problem and realize that given an object reference, we don't need any iteration or further access to the list.
All we need to do is to assign
next.val of the given node to
next of the node itself. Lastly, because it's Swift, we need to make sure to obey to the rules of handling optionals properly.