Study the article about sorting the array by even/odd number, placing odd numbers before even number. And then, next question, sorting the array by negative/positive number, and keep the order. - on May 4, 2015, 8;30pm - 11:00pm, read 2. 5 hours.
First question, 输入一个整数数组,调整数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分。要求时间复杂度为O(n)
Read the paper: STABLE MINIMUM SPACE PARTITIONING IN LINEAR TIME Next question: 一个未排序整数数组,有正负数,重新排列使负数排在正数前面,并且要求不改变原来的正负数之间相对顺序,比如: input: 1,7,-5,9,-12,15 ans: -5,-12,1,7,9,15 要求时间复杂度O(n),空间O(1)
No comments:
Post a Comment