题目:奇偶分割数组
来源:互联网 发布:淘宝如何申请海外买手 编辑:程序博客网 时间:2024/05/15 11:40
分割一个整数数组,使得奇数在前偶数在后。
您在真实的面试中是否遇到过这个题?Yes
样例
给定 [1, 2, 3, 4]
,返回 [1, 3, 2, 4]
。
挑战
标签 Expand在原数组中完成,不使用额外空间。
相关题目 Expand
public class Solution {
/**
* @param nums: an array of integers
* @return: nothing
*/
public void partitionArray(int[] nums) {
// write your code here;
int i = 0;
int j = nums.length-1;
while(j>i){
while(nums[i]%2==1){
i++;
}
while(nums[j]%2==0){
j--;
}
if(j>i){
int tmp = nums[i];
nums[i] = nums[j];
nums[j] = tmp;
}
i++;j--;
}
}
}
0 0
- 题目:奇偶分割数组
- 奇偶分割数组
- LintCode_373_奇偶分割数组
- 奇偶分割数组
- lintcode ----奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- lintcode,奇偶分割数组
- LintCode373:奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- Lintcode奇偶分割数组
- 奇偶分割数组-LintCode
- lintcode-奇偶分割数组-373
- 奇偶分割数组(LintCode)
- 奇偶数组分割,原地进行
- Java实现-奇偶分割数组
- linux 常见命令 ,实用才是硬道理.
- 跳进程序媛这个坑
- 题目:在二叉查找树中插入节点
- 给中国学生的第七封信:21世纪最需要的7种人才
- UVA 674 - Coin Change
- 题目:奇偶分割数组
- C++多维排序
- uva 1623 - Enter The Dragon
- 内存碎片和内存泄露
- 题目:子数组之和
- server 2008 80端口无法关闭
- 什么是进程
- Maximum Gap
- Swift开发教程--如何给UITextView添加圆角边框