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"的更多相关文章

  1. 373. Partition Array by Odd and Even【LintCode java】

    Description Partition an integers array into odd number first and even number second. Example Given  ...

  2. Lintcode373 Partition Array by Odd and Even solution 题解

    [题目描述] Partition an integers array into odd number first and even number second. 分割一个整数数组,使得奇数在前偶数在后 ...

  3. Partition Array by Odd and Even

    Partition an integers array into odd number first and even number second. Example Given [, , , ], , ...

  4. lintcode 容易题:Partition Array by Odd and Even 奇偶分割数组

    题目: 奇偶分割数组 分割一个整数数组,使得奇数在前偶数在后. 样例 给定 [1, 2, 3, 4],返回 [1, 3, 2, 4]. 挑战 在原数组中完成,不使用额外空间. 解题: 一次快速排序就可 ...

  5. Lintcode: Partition Array

    Given an array "nums" of integers and an int "k", Partition the array (i.e move ...

  6. LintCode 373: Partition Array

    LintCode 373: Partition Array 题目描述 分割一个整数数组,使得奇数在前偶数在后. 样例 给定[1, 2, 3, 4],返回[1, 3, 2, 4]. Thu Feb 23 ...

  7. 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 ...

  8. lintcode 中等题:partition array 数组划分

    题目 数组划分 给出一个整数数组nums和一个整数k.划分数组(即移动数组nums中的元素),使得: 所有小于k的元素移到左边 所有大于等于k的元素移到右边 返回数组划分的位置,即数组中第一个位置i, ...

  9. Partition Array

    Given an array nums of integers and an int k, partition the array (i.e move the elements in "nu ...

随机推荐

  1. 用rem来做响应式开发

    强烈推荐这篇文章:<web app 变革之rem> px转rem工具:<px转rem工具> 由于最近在做公司移动项目的重构,因为要实现响应式的开发,所以大量使用到了rem的单位 ...

  2. ORA-12545: 因目标主机或对象不存在, 连接失败

    ORA-12545: 因目标主机或对象不存在, 连接失败 1. 问题描述 XP系统下同时安装了AX1应用程序和升级版AX2,连接同一个在本机Oracle客户端上配置的连接实例,其中AX2显示链接成功, ...

  3. 使用ingress qdisc和ifb进行qos

    ifb   The Intermediate Functional Block device is the successor to the IMQ iptables module that was ...

  4. java zip文件的解压缩(支持中文文件名)

    用的apache的ant包,下载导入即可.由于过程比较简单,直接上代码. 代码可直接复制使用. 如果想在android上使用,记得要在AndroidManifest.xml里添加权限: <use ...

  5. Core Java Volume I — 3.4. Variables

    3.4. VariablesIn Java, every variable has a type. You declare a variable by placing the type first, ...

  6. ZOJ Problem Set - 3635

    题目大意 有n个从1..n标号的座位,按时间顺序给出每个客人来的时候是坐在第几个空座位,最后给若干个询问问第i号客人坐在哪里 分析 线段树+二分 // Fast Sequence Operations ...

  7. nginx+tomcat集群配置(1)---根目录设定和多后端分发配置

    前言: 对于javaer而言, nginx+tomcat集群配置, 已然成了web应用部署的主流. 大公司如此, 小公司亦然. 对于个人开发者而言, 资源有限, 往往多个web应用混部于一台服务器(云 ...

  8. HDU 4358 莫队算法+dfs序+离散化

    Boring counting Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others)T ...

  9. Dialog样式

    <style name="load_dialog" parent="@android:style/Theme.Dialog"> <item n ...

  10. activiti工作流数据库表详细介绍 (23张表)

    Activiti的后台是有数据库的支持,所有的表的表名都以ACT_开头,表名的第二部分是用来表示表的用途的两个字母标识. 用途也和服务的API对应. ACT_RE_*: 'RE'表示repositor ...