time:O(nlogn),space:O(n)