add Solution with O(N) time complexity