中级农民

- 积分
- 100
- 学分
- 个
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- UID
- 50216
- 注册时间
- 2012-2-1
- 最后登录
- 1970-1-1
- 在线时间
- 小时
- 好友
- 收听
- 听众
- 日志
- 相册
- 帖子
- 主题
- 分享
- 精华
|
本楼: |
👍
0% (0)
|
|
0% (0)
👎
|
全局: |
👍 100% (2) |
|
0% (0) 👎 |
Use quick sort. When comparing numbers any odd number is presented as its negative. O(N log N)
This is equivalent to:
1. Preprocess an array so that all odd numbers are negative to the original
2. Sort the whole array
3. Post-process the array so that all odd numbers are negative to the current (which are all negative)
For example
1234567
when comparing, all odd numbers are in its negative presentation
-1 2 -3 4 -5 6 -7
After Sort:
-7 -5 -3 -1 2 4 6
But the number itself is not actually inverted
7 5 4 1 2 4 6
It fits the requirement of top portion of the array contains odd numbers, bottom portion contains even numbers. The odd numbers are to be sorted in descending order and the even numbers in ascending order. |
|