【Leetcode_easy】905. Sort Array By Parity
problem
solution1:
class Solution {
public:
vector<int> sortArrayByParity(vector<int>& A) {
vector<int> even, odd;
for(auto a:A)
{
if(a%==) even.push_back(a);
else odd.push_back(a);
}
even.insert(even.end(), odd.begin(), odd.end());
return even;
}
};
solution2:
class Solution {
public:
vector<int> sortArrayByParity(vector<int>& A) {
for(int i=, j=; j<A.size(); j++)
{
if(A[j]%==)
{
swap(A[i++], A[j]);//i-even,j-odd;
}
}
return A;
}
};
参考
1. Leetcode_easy_905. Sort Array By Parity;
2. discuss;
完
【Leetcode_easy】905. Sort Array By Parity的更多相关文章
- 【Leetcode_easy】922. Sort Array By Parity II
problem 922. Sort Array By Parity II solution1: class Solution { public: vector<int> sortArray ...
- 【leetcode】905. Sort Array By Parity
题目如下: 解题思路:本题和[leetcode]75. Sort Colors类似,但是没有要求在输入数组本身修改,所以难度降低了.引入一个新的数组,然后遍历输入数组,如果数组元素是是偶数,插入到新数 ...
- 【LeetCode】905. Sort Array By Parity 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 自定义sorted函数的cmp 日期 题目地址:h ...
- 【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. ...
- 【LeetCode】922. Sort Array By Parity II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用奇偶数组 排序 奇偶数位置变量 日期 题目地址: ...
- 【leetcode】922. Sort Array By Parity II
题目如下: 解题思路:非常简单的题目,引入两个变量oddInx = 1和evenInx = 0,和与A等长的结果数组res.然后遍历A,如果A[i]为偶数,则令res[evenInx] = A[i], ...
- 【LEETCODE】41、905. Sort Array By Parity
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 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 ...
- 905. Sort Array By Parity - LeetCode
Question 905. Sort Array By Parity Solution 题目大意:数组排序,偶数放前,奇数在后,偶数的数之间不用管顺序,奇数的数之间也不用管顺序 思路:建两个list, ...
随机推荐
- Sublime 原版安装
sublime text3 安装方法 ① 官网下载安装 https://www.sublimetext.com/3 ② 更改hosts文件 具体方法如下: windows系统的hosts文件在C:\W ...
- C# 判断程序是否执行 进行启动或前台显示
#region 显示程序 [DllImport("user32.dll", EntryPoint = "FindWindow")] public static ...
- CF19D Points 平衡树
题意:支持插入/删除点 $(x,y)$,查询一个点右上方横坐标与之最接近的点坐标. 我们可以对于每一个操作过的横坐标都开一个 $set$,然后再开一个平衡树,维护每个横坐标上最大的纵坐标. 然后查询点 ...
- Nginx 安装配置【必须把文件到放到机器上】
[必须把所有下载的gz文件到放到机器上:编译] 1.安装nginx之前的编译软件 yum -y install make zlib zlib-devel gcc-c++ libtool openss ...
- shell脚本之字符串运算的使用
字符串运算符 下表列出了常用的字符串运算符,假定变量 a 为 "abc",变量 b 为 "efg": 运算符 说明 举例 = 检测两个字符串是否相等,相等返回 ...
- 2019.10.25字符串——zr
题意: 给你两个字符串,由01组成:求他们两个的最短公共非子序列,要求字典序最小: 非公共子序列:都不是这两个字符串的子序列: 本人只会暴力啊,二进制枚举稳拿15分: 然而这道题其实是一个最短路题: ...
- call 和 apply 方法
1:每个函数都包含两个非继承而来的方法:call(),apply(). 2:call方法和apply方法作用是一样的. 下边是call的使用例子: window.color = 'red'; docu ...
- 查看 ssh 攻击 和 攻击成功者
查看攻击失败记录: grep "Failed password for invalid user admin" /var/log/auth.log 查看攻击成功的记录: grep ...
- revenue
美 ['revənju] 英 ['revənjuː] n.收益:营业额:税务署 网络收入:税收:岁入
- 与 ES5 相比,React 的 ES6 语法有何不同?
以下语法是 ES5 与 ES6 中的区别: 1.require 与 import // ES5 var React = require('react'); // ES6 import React fr ...