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

very easy