v5 time O(n) space O(1) Accepted