time:O(logn),space:O(1)
time:O(nlogn),space:O(n^2)