Lintcode奇偶分割数组
来源:互联网 发布:计生委招聘 知乎 编辑:程序博客网 时间:2024/05/29 13:09
奇偶分割数组
分割一个整数数组,使得奇数在前偶数在后。
样例
给定 [1, 2, 3, 4]
,返回 [1, 3, 2, 4]
。
挑战
在原数组中完成,不使用额外空间。
public class Solution {
/*
* @param nums: an array of integers
* @return: nothing
*/
public void partitionArray(int[] nums) {
// write your code here
int a=0;
int temp=0;
for(int i=0;i<nums.length;i++){
if(nums[i]%2!=0){
temp=nums[a];
nums[a]=nums[i];
nums[i]=temp;
a++;
}
}
}
}
阅读全文
0 0
- lintcode ----奇偶分割数组
- lintcode,奇偶分割数组
- Lintcode奇偶分割数组
- 奇偶分割数组-LintCode
- lintcode-奇偶分割数组-373
- 奇偶分割数组(LintCode)
- [LintCode]373.奇偶分割数组
- LintCode-剑指Offer-(373)奇偶分割数组
- 题目:奇偶分割数组
- 奇偶分割数组
- LintCode_373_奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- LintCode373:奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- 奇偶分割数组
- 实验三:内部模块化的命令行菜单小程序V2.0
- zuul配置
- Face The Right Way
- linux/ubuntu下IPython、IPython Notebook(jupyter)的安装和基本使用
- JAVA程序初始化的顺序是怎么样的
- Lintcode奇偶分割数组
- 全局修改默认字体,通过反射也能做到
- Struts1工作原理
- Java解析json文件的方法--直接拷贝可以使用
- 详解线索二叉树
- 2016ICPC大连站 A
- 剑指编程(1)
- mycat2.0配置文件schema.yml参数说明(chemaType)
- 操作系统笔记