Update solution.py

Solution found in O(N) time and O(1) space.