LintCode "Partition Array by Odd and Even"
One pass in-place solution: all swaps.
class Solution {
public:
/**
* @param nums: a vector of integers
* @return: nothing
*/
void partitionArray(vector<int> &nums) {
size_t len = nums.size();
int i = , io = , ie = len - ;
while (io < ie)
{
int v = nums[i];
if (v & 0x1) // odd
{
swap(nums[i], nums[io++]);
}
else // even
{
swap(nums[i], nums[ie--]);
}
i = io;
}
}
};
LintCode "Partition Array by Odd and Even"的更多相关文章
- 373. Partition Array by Odd and Even【LintCode java】
Description Partition an integers array into odd number first and even number second. Example Given ...
- Lintcode373 Partition Array by Odd and Even solution 题解
[题目描述] Partition an integers array into odd number first and even number second. 分割一个整数数组,使得奇数在前偶数在后 ...
- Partition Array by Odd and Even
Partition an integers array into odd number first and even number second. Example Given [, , , ], , ...
- lintcode 容易题:Partition Array by Odd and Even 奇偶分割数组
题目: 奇偶分割数组 分割一个整数数组,使得奇数在前偶数在后. 样例 给定 [1, 2, 3, 4],返回 [1, 3, 2, 4]. 挑战 在原数组中完成,不使用额外空间. 解题: 一次快速排序就可 ...
- Lintcode: Partition Array
Given an array "nums" of integers and an int "k", Partition the array (i.e move ...
- LintCode 373: Partition Array
LintCode 373: Partition Array 题目描述 分割一个整数数组,使得奇数在前偶数在后. 样例 给定[1, 2, 3, 4],返回[1, 3, 2, 4]. Thu Feb 23 ...
- A. Array with Odd Sum Round #617(水题)
A. Array with Odd Sum time limit per test 1 second memory limit per test 256 megabytes input standar ...
- lintcode 中等题:partition array 数组划分
题目 数组划分 给出一个整数数组nums和一个整数k.划分数组(即移动数组nums中的元素),使得: 所有小于k的元素移到左边 所有大于等于k的元素移到右边 返回数组划分的位置,即数组中第一个位置i, ...
- Partition Array
Given an array nums of integers and an int k, partition the array (i.e move the elements in "nu ...
随机推荐
- 完美解决IE6不支持position:fixed的bug
示例代码: <!DOCTYPE html><html><head><meta http-equiv="Content-Type" cont ...
- easyui accordion—手风琴格子始终展开和多个格子展开
来源:http://www.cnblogs.com/tylerdonet/p/3531844.html 始终打开有时候可能会很管用,其实就是一个设置问题.这里就不再介绍引用的资源了,这里只看看html ...
- Java--常用类
1.方法中参数传递:值传递 基本数类型:具体的实际值 引用数据类型:对象的地址值 2.继承:关键字:extends单继承继承父类的非私有成员多重继承 2.权限的修饰符:private 只能在当前类的内 ...
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列
A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- ZOJ 1205 Martian Addition
原题链接 题目大意:大数,20进制的加法计算. 解法:convert函数把字符串转换成数组,add函数把两个大数相加. 参考代码: #include<stdio.h> #include&l ...
- HTTP.sys漏洞验证及防护
使用发包工具构造http请求包检测 以fiddler工具为例,构造如下图的请求包: 1 GET http://192.168.174.145/ HTTP/1.12 Host: 192.168.174. ...
- AttributeError: 'NoneType' object has no attribute 'bytes' python3.4 win64
解决方法: easy_install -U pip 详见: https://github.com/pypa/pip/issues/2669
- 《剑指Offer》之替换空格
1.题目描述 请实现一个函数,将一个字符串中的空格替换成"%20".例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 2.代码实 ...
- CUDA Thread Indexing
1D grid of 1D blocks __device__ int getGlobalIdx_1D_1D() { return blockIdx.x *blockDim.x + threadIdx ...
- 非对称SVD电影推荐系统
采用1M MovieLensz数据(80%train, 20%test, UserIDs range between 1 and 6040 ,MovieIDs range between 1 and ...