[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 ...
随机推荐
- StarWind Storage Appliance
https://www.starwindsoftware.com/starwind-storage-appliance?gclid=CLzH8oGyptICFbIW0wodNuYG1Q
- Angucomplete —— AngularJS 自动完成输入框
分享 <关于我> 分享 [中文纪录片]互联网时代 http://pan.baidu.com/s/1qWkJfcS 分享 <HTML开发MacOSAp ...
- C#调用记事本并填写内容
using System.Runtime.InteropServices; using System.Diagnostics; [DllImport("User32.DLL") ...
- Qt第三方圆形进度条-及其改进
Qt第三方圆形进度条的改进 要实现一个圆形的进度条功能,在网上找到一个比较出名的第三方封装类:QRoundProgressBar,地址:sourceforge 的 QRoundProgressBar ...
- ACL FAQ
acl 下载地址:https://sourceforge.net/projects/acl/https://github.com/zhengshuxin/acl/http://git.oschina. ...
- vue.js异步上传文件前后端代码
上传文件前端代码如下: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&q ...
- 点菜网---Java开源生鲜电商平台-系统架构图(源码可下载)
点菜网---Java开源生鲜电商平台-系统架构图(源码可下载) 1.点菜网-生鲜电商平台的价值与定位. 生鲜电商平台是一家致力于打造全国餐饮行业智能化.便利化.平台化与透明化服务的创新型移动互联网平台 ...
- GIS热力图制作与位置大数据分析
最近有很多朋友咨询位置数据.热力图等等东西,我一一进行了解答,但是个人精力实在有限,特写一个博客进行详细技术说明,其实这个东西位置数据.百度地图POI.高德地图POI等数据爬取.存储都较为简单,热力图 ...
- 【fullGC】内存监控工具
什么是fullGC: 从年轻代空间(包括 Eden 和 Survivor 区域)回收内存被称为 Minor GC,对老年代GC称为Major GC,而Full GC是对整个堆来说的,在最近几个版本的J ...
- OpenCV常用数据结构和函数
点的表示:Point类 Point类数据结构表示二维坐标系下的点,即由其图像坐标x,y指定的2D点. 用法如下 Point point; point.x = 10; point.y = 8; 或者 P ...