[回复]
[修改] [删除]
[返回版面]
|
1 |
作者: admin, 讨论版: 算法集锦, 发表时间: 2015-03-05 02:34:11 PST
标题: Separate odd and even numbers
关键字: Array MS
Given an array, sort the array in such a way that the first part of the sorted array contains odd numbers, and the second part contains even numbers. The first part has to be sorted in descending order and the second part in ascending order. Not extra array, no pre or post processing and it has to use a conventional sorting mechanism.
From here
--
Solution:
Iterate through the array and multiply all odd numbers by -1,Sort the array, again multiply the odd numbers by -1. O(n)+O(nlogn)+O(n)=O(nlogn)
--
※ 来源: homecox.com [来自: 72.]
|
|
|