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