Added my solution in comments