[leetcode] 905. Sort Array By Parity [easy]
原题链接
很水的一道题,就是数组内部交换。
水题就想着减少复杂度嘛,于是学到一种交换写法。
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]的更多相关文章
- 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 ...
- [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, ...
- LeetCode 905 Sort Array By Parity 解题报告
题目要求 Given an array A of non-negative integers, return an array consisting of all the even elements ...
- LeetCode 905. Sort Array By Parity 按奇偶校验排列数组
题目 Given an array A of non-negative integers, return an array consisting of all the even elements of ...
- 【LEETCODE】41、905. Sort Array By Parity
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 905. Sort Array By Parity - LeetCode
Question 905. Sort Array By Parity Solution 题目大意:数组排序,偶数放前,奇数在后,偶数的数之间不用管顺序,奇数的数之间也不用管顺序 思路:建两个list, ...
- 【Leetcode_easy】905. Sort Array By Parity
problem 905. Sort Array By Parity solution1: class Solution { public: vector<int> sortArrayByP ...
- [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 ...
- 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 ...
随机推荐
- 高效的DDoS攻击探测与分析工具 – FastNetMon
快速使用Romanysoft LAB的技术实现 HTML 开发Mac OS App,并销售到苹果应用商店中. <HTML开发Mac OS App 视频教程> 土豆网同步更新:http: ...
- OpenSSL包括了8个功能
什么是OpenSSL 众多的密码算法.公钥基础设施标准以及SSL协议,或许这些有趣的功能会让你产生实现所有这些 算法和标准的想法.果真如此,在对你表示敬佩的同时,还是忍不住提醒你:这是一个令人望而生畏 ...
- python中的变量,字符串,用户交互,if语句
一:python介绍 python的创始人为吉多·范罗苏姆,创始时间是1989年. 1python是一门什么样的语言 python是一门解释型弱类型语言★ 弱类型:弱类型的变量可以变,强类型的变量不能 ...
- fullpage.js使用方法
了解: [1]之所以叫做fullpage,是因为它可以全屏滚动,拥有强大的功能. [2]它依赖于jQuery库,所以在使用fullpage之前先引入jQuery库. 使用: [1]<link r ...
- 共识协议——RAFT&PBFT
区块链是一个没有中央权威的分布式对等系统.虽然权力下放可以防止各方的腐败行为,但是它必需要有一个可靠的共识协议来作出决策,让分散在世界各地的节点可以形成一致的意见.常见的共识算法有比特币采用的POW, ...
- Elasticsearch的使用
我这边是以elasticsearch-2.4.3为例:引入maven <dependency> <groupId>org.elasticsearch.client</gr ...
- Hive 学习之路(四)—— Hive 常用DDL操作
一.Database 1.1 查看数据列表 show databases; 1.2 使用数据库 USE database_name; 1.3 新建数据库 语法: CREATE (DATABASE|SC ...
- 【转】三次握手——https为什么更安全
三次握手与四次挥手: https://blog.csdn.net/legend050709/article/details/39804519 https://blog.csdn.net/luoyoub ...
- redis安装与php安装redis模块
一.安装redis 1.下载 wget https://github.com/antirez/redis/archive/2.8.23.tar.gz 2.解压缩 tar -zxvf 2.8.23.ta ...
- Codeforces Round #563 (Div. 2)B
B.Ehab Is an Odd Person 题目链接:http://codeforces.com/contest/1174/problem/B 题目 You’re given an array a ...