Optimal way to check for Keypress on collision

Here is a screenshot to better understeand what i mean:


Which approach is better and why?