2 ms·
This is exactly the right answer. There are two cases here (1. when the target is at the front of the list and necessitates changing the head of list, and 2. w
by haskman 6y ago
This is exactly the right answer.
There are two cases here (1. when the target is at the front of the list and necessitates changing the head of list, and 2. when the head doesn't need to be changed.) You handle both the cases separately.
Both the classical and the "elegant" versions are worse than this one.
- mjburgess 6y agoLinus' point is that this way of thinking produces this "edge case". There is no "head case", all members of the list are the same. The head isn't a special element.