原题链接

很水的一道题,就是数组内部交换。

水题就想着减少复杂度嘛,于是学到一种交换写法。

class Solution
{
public:
vector<int> sortArrayByParity(vector<int> &A)
{
int i = 0, j = A.size()-1;
while (i < j)
{
if (A[i] & 0x01)
{
A[i] ^= A[j];
A[j] ^= A[i];
A[i] ^= A[j];
--j;
}
else
++i;
}
return A;
}
};

[leetcode] 905. Sort Array By Parity [easy]的更多相关文章

  1. LeetCode 905. Sort Array By Parity

    905. Sort Array By Parity Given an array A of non-negative integers, return an array consisting of a ...

  2. [LeetCode] 905. Sort Array By Parity 按奇偶排序数组

    Given an array A of non-negative integers, return an array consisting of all the even elements of A, ...

  3. LeetCode 905 Sort Array By Parity 解题报告

    题目要求 Given an array A of non-negative integers, return an array consisting of all the even elements ...

  4. LeetCode 905. Sort Array By Parity 按奇偶校验排列数组

    题目 Given an array A of non-negative integers, return an array consisting of all the even elements of ...

  5. 【LEETCODE】41、905. Sort Array By Parity

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

  6. 905. Sort Array By Parity - LeetCode

    Question 905. Sort Array By Parity Solution 题目大意:数组排序,偶数放前,奇数在后,偶数的数之间不用管顺序,奇数的数之间也不用管顺序 思路:建两个list, ...

  7. 【Leetcode_easy】905. Sort Array By Parity

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

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

随机推荐

  1. BI-学习之 新概念介绍

    什么是统一维度模型 层次结构.级别.成员和度量值 什么是MDX MDX与SQL的区别 什么是数据仓库 什么是OLAP数据分析引擎 BI企业级解决方案 什么是统一维度模型 维度(dimension)是描 ...

  2. ubuntu 14.04搭建tensorflow-gpu开发环境

    一.安装nvidia显卡驱动 去navidia官网查看最新的驱动版本号:navidia官网:http://www.geforce.cn/drivers 找到显卡对应的驱动下载,例如下载的驱动为 NVI ...

  3. C#基础原理拾遗——引用类型的值传递和引用传递

    以前写博客不深动,只搭个架子,像做笔记,没有自己的思考,也没什么人来看.这个毛病得改,就从这一篇开始- 最近准备面试,深感基础之重要,奈何我不是计算机科班出身,基础方面有些捉襟见肘.短期怎么补?做面实 ...

  4. 使用Scrapy爬取图片入库,并保存在本地

    使用Scrapy爬取图片入库,并保存在本地 上 篇博客已经简单的介绍了爬取数据流程,现在让我们继续学习scrapy 目标: 爬取爱卡汽车标题,价格以及图片存入数据库,并存图到本地 好了不多说,让我们实 ...

  5. TCP使用注意事项总结

    目录 发送或者接受数据过程中对端可能发生的情况汇总 本端TCP发送数据时对端进程已经崩溃 本端TCP发送数据时对端主机已经崩溃 本端TCP发送数据时对端主机已经关机 某个连接长时间没有数据流动 TCP ...

  6. Centos7离线安装mysql8

    linux版本:Centois7 mysql版本:5.7 一.安装 1.下载mysql离线安装包 下载地址:https://dev.mysql.com/downloads/mysql/ 选择如下: [ ...

  7. Codeforces Round #565 (Div. 3) B

    B. Merge it! 题目链接:http://codeforces.com/contest/1176/problem/B 题目 You are given an array a consistin ...

  8. 【前端优化】js图片懒加载及优化

    一.前言 为啥要对图片使用懒加载?我们首先来聊聊这个问题,对于页面来说架子啊速度影响着最大的就是图片,一张普通的图片可以达到4-5M的大小,而代码压缩也就只有几十KB.当页面图片过多的时候,页面加载速 ...

  9. 在 ASP.NET Web API 中使用 Attribute 统一处理异常

    并非所有的异常都需要 try-catch 进行重复的处理,这会导致大量的重复性代码,一旦后续系统出现异常处理机制的修改,随着代码量增多,修改也会变的更加困难. ASP.NET Web API 中特别增 ...

  10. Google play中下载apk

    在 Google play中下载apk:先在Google play中找到该apk,再去找APK downloader(https://www.allfreeapk.com/),Google play的 ...