原题链接

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

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

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. Delphi中文件流的使用方法

    在Delphi中,所有流对象的基类为TStream类, 其中定义了所有流的共同属性和方法.TStream类中定义的属性介绍如下: 1.Size: 此属性以字节返回流中数据大小. 2.Position: ...

  2. MFC中的模态对话框与非模态对话框,模态对话框测试

    http://blog.csdn.net/u010839382/article/details/52972427 http://blog.csdn.net/u010839382/article/det ...

  3. 源码解读·RT-Thread小内存管理算法分析

    这篇文章最初发布在RT-Thread官方论坛中,最近准备整理放到博客中来让更多人一起探讨学习. 2012年9月28日星期五 前言: 母语能力有限 概述: 这篇文字和大家分享一下今晚对RT-Thread ...

  4. 微服务之服务注册与发现--Consul(转载)

    http://blog.csdn.net/buxiaoxia/article/details/69788114 https://www.cnblogs.com/xiaohanlin/p/8016803 ...

  5. Python random() 生成随机数

    random() 函数中常见的函数如下: #!/usr/bin/python # -*- coding: UTF-8 -*- import random print( random.randint(1 ...

  6. ZOJ 3981:Balloon Robot(思维+递推)

    题目链接 题意 有n支队在m个位置上做题,有一个机器人位置1到位置m再到位置1循环走派发气球,当队伍a在时间b做完了一道题目的时候,假如机器人走到队伍a的位置的时间为c,那么这个队伍的不开心值就是c- ...

  7. Codeforces 348B:Apple Tree(DFS+LCM+思维)

    http://codeforces.com/contest/348/problem/B 题意:给一棵树,每个叶子结点有w[i]个苹果,每个子树的苹果数量为该子树所有叶子结点苹果数量之和,要使得每个结点 ...

  8. 使用JavaScript实现量化策略并发执行——封装Go函数

    在实现量化策略时,很多情况下,并发执行可以降低延时提升效率.以对冲机器人为例,需要获取两个币的深度,顺序执行的代码如下: 请求一次rest API存在延时,假设是100ms,那么两次获取深度的时间实际 ...

  9. os.path.join路径拼接的问题

    问题一: import os a = os.path.join("/test1", "/test2") print(a) b = os.path.join(&q ...

  10. C# “从元数据”

    所谓元数据.其实是指由微软所封装的类..这些类你可以查看.但是无法修改. 元数据是一种二进制信息,用以对存储在公共语言运行库可移植可执行文件 (PE) 文件或存储在内存中的程序进行描述.将您的代码编译 ...