problem

922. Sort Array By Parity II

solution1:

class Solution {
public:
vector<int> sortArrayByParityII(vector<int>& A) {
int n = A.size();
for(int i=, j=; i<n, j<n; )
{
while(i<n && A[i]%==) i += ;
while(j<n && A[j]%==) j += ;
if(j<n) swap(A[i], A[j]);
}
return A;
}
};

参考

1. Leetcode_easy_922. Sort Array By Parity II;

2. discuss;

【Leetcode_easy】922. Sort Array By Parity II的更多相关文章

  1. 【leetocde】922. Sort Array By Parity II

    Given an array of integers nums, half of the integers in nums are odd, and the other half are even.  ...

  2. 【LeetCode】922. Sort Array By Parity II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用奇偶数组 排序 奇偶数位置变量 日期 题目地址: ...

  3. 【leetcode】922. Sort Array By Parity II

    题目如下: 解题思路:非常简单的题目,引入两个变量oddInx = 1和evenInx = 0,和与A等长的结果数组res.然后遍历A,如果A[i]为偶数,则令res[evenInx] = A[i], ...

  4. 【Leetcode_easy】905. Sort Array By Parity

    problem 905. Sort Array By Parity solution1: class Solution { public: vector<int> sortArrayByP ...

  5. 【LEETCODE】42、922. Sort Array By Parity II

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  6. LeetCode 922. Sort Array By Parity II C++ 解题报告

    922. Sort Array By Parity II 题目描述 Given an array A of non-negative integers, half of the integers in ...

  7. 【leetcode】905. Sort Array By Parity

    题目如下: 解题思路:本题和[leetcode]75. Sort Colors类似,但是没有要求在输入数组本身修改,所以难度降低了.引入一个新的数组,然后遍历输入数组,如果数组元素是是偶数,插入到新数 ...

  8. [LeetCode] 922. Sort Array By Parity II 按奇偶排序数组之二

    Given an array A of non-negative integers, half of the integers in A are odd, and half of the intege ...

  9. 【LeetCode】905. Sort Array By Parity 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 自定义sorted函数的cmp 日期 题目地址:h ...

随机推荐

  1. 浏览器中点击链接,跳转qq添加好友的实现方式

    做android三年了,都不知道到底干了啥,现在好好研究应该来得及,哈哈哈,希望看到文章的人共勉,哈哈哈(新手写文章,大佬轻喷,呜呜呜~) 好了,这篇只是记录下,项目中遇到的坑(MMP测试),哈哈哈, ...

  2. P4357 [CQOI2016]K远点对

    题意:给定平面中的 \(n\) 个点,求第 \(K\) 远的点对之间的距离,\(n\leq 1e5,K\leq min(100,\frac{n\times (n-1)}{2})\) 题解:kd-tre ...

  3. loj #6485. LJJ 学二项式定理 单位根反演

    新学的黑科技,感觉好nb ~ #include <bits/stdc++.h> #define ll long long #define setIO(s) freopen(s". ...

  4. Redis中的缓存雪崩与缓存穿透

    1.缓存雪崩 1.1什么是缓存雪崩? 如果我们的缓存挂掉了,这意味着我们的全部请求都跑去数据库了. 我们都知道Redis不可能把所有的数据都缓存起来(内存昂贵且有限),所以Redis需要对数据设置过期 ...

  5. AtCoder Grand Contest 012题解

    传送门 \(A\) 肯定是后面每两个陪最前面一个最优 typedef long long ll; const int N=5e5+5; int a[N],n;ll res; int main(){ s ...

  6. 洛谷P1325 雷达安装

    题目 考虑对于一个小岛,如果有雷达可以覆盖它,则这些雷达肯定在一个区间里,则原题内容则变为区间选点问题 #include <bits/stdc++.h> using namespace s ...

  7. Hbase监控指标项

    名词解释 JMX:Java Management Extensions,用于用于Java程序扩展监控和管理项 GC:Garbage Collection,垃圾收集,垃圾回收机制 指标项来源 主机名 u ...

  8. ICEM-气化炉

    原视频下载地址:https://yunpan.cn/cuPJWRHUJKXIL  访问密码 d379

  9. postman_

    form-data 相当于Content-Type:multipart/form-data;它会将表单的数据处理为一条消息,以标签为单元,用分隔符分开.既可以上传键值对,也可以上传文件. x-www- ...

  10. env (arcpy)

    addOutputsToMap (读写) 设置是否应将工具产生的输出数据集添加至应用程序显示. Boolean autoCommit (读写) 支持“自动提交”环境的工具将在 ArcSDE 事务中进行 ...