v2 time O(n) space O(log(n)) Accepted