Problem:
Numbers, arrange them such that negative numbers are to the left of 0 and positive numbers are to the right of 0.
The goal is to rearrange the numbers so that all negative values appear before zero, and all positive values appear after zero.
这道题的核心是对数组按符号进行重排:把所有负数放到 0 的左边,把所有正数放到 0 的右边。通常可以使用双指针或一次遍历的分区思路来完成,时间复杂度可做到线性。若题目默认 0 也参与排列,需要注意 0 的位置通常位于负数与正数之间;如果没有额外要求,一般只需保证相对顺序以外的分区正确即可。
正文完