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 ...
随机推荐
- EASYRECOVERY_3.3.29包含注册机、都教授数据恢复含注册码
用EASYRECOVERY恢复过U盘,和回收站永久清空的东西.效果很好.但疑惑doc,docx,后者恢复效果特别好 都教授没用过,别人买的,没用,很贵. 每次用,都找不着,还要重新淘宝买.这次分享给大 ...
- QMP ( qemu monitor protocol ) and Different ways of accessing it
The QEMU Monitor Protocol (QMP) is a JSON-based protocol which allows applications to communicate wi ...
- hexo系列教程
hexo系列教程来源: http://zipperary.com/2013/05/28/hexo-guide-1/ hexo系列教程:(一)hexo介绍 什么是hexo hexo是一个基于Node.j ...
- static讲解
static表示"全局"或者"静态"的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念. 被stati ...
- poj 1260 dp
Description In Pearlania everybody is fond of pearls. One company, called The Royal Pearl, produces ...
- Matlab GUI设计中的一些常用函数
Matlab GUI常用函数总结 % — 文件的打开.读取和关闭% — 文件的保存% — 创建一个进度条% — 在名为display的axes显示图像,然后关闭% — 把数字转化为时间格式% — ch ...
- zoj3623 Battle Ships ——完全背包?简单DP!|| 泛化背包
link:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3623 看起来像完全背包,但是物品价值是变化的,所以很多人搞的很复 ...
- leetcode 96 Unique Binary Search Trees ----- java
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- 在IE地址栏输入JS的有趣效果
1.编辑网页 在地址栏输入下面的代码按enter,网页上所有元素都能变成可编辑状态,你可以移动.调整元素大小.如果你只是讨厌某个网站想发泄一下,我建议你使用NetDisater. 代码如下: java ...
- InvokeRequired和Invoke
C#中禁止跨线程直接访问控件,InvokeRequired是为了解决这个问题而产生的,当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它.此时它将会在内部调用ne ...