【Leetcode_easy】922. Sort Array By Parity II
problem
solution1:
class Solution {
public:
vector<int> sortArrayByParityII(vector<int>& A) {
int n = A.size();
for(int i=, j=; i<n, j<n; )
{
while(i<n && A[i]%==) i += ;
while(j<n && A[j]%==) j += ;
if(j<n) swap(A[i], A[j]);
}
return A;
}
};
参考
1. Leetcode_easy_922. Sort Array By Parity II;
2. discuss;
完
【Leetcode_easy】922. Sort Array By Parity II的更多相关文章
- 【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_easy】905. Sort Array By Parity
problem 905. Sort Array By Parity solution1: class Solution { public: vector<int> sortArrayByP ...
- 【LEETCODE】42、922. Sort Array By Parity II
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 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 ...
- 【leetcode】905. Sort Array By Parity
题目如下: 解题思路:本题和[leetcode]75. Sort Colors类似,但是没有要求在输入数组本身修改,所以难度降低了.引入一个新的数组,然后遍历输入数组,如果数组元素是是偶数,插入到新数 ...
- [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】905. Sort Array By Parity 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 自定义sorted函数的cmp 日期 题目地址:h ...
随机推荐
- JAVA读取XML并打印
在G盘下新建XML文档:person.xml,XML代码: <?xml version="1.0" encoding="utf-8"?> <s ...
- MySQL 索引原理以及慢查询优化
本文以MySQL数据库为研究对象,讨论与数据库索引相关的一些话题.特别需要说明的是,MySQL支持诸多存储引擎,而各种存储引擎对索引的支持也各不相同,因此MySQL数据库支持多种索引类型,如BTree ...
- ML,DL核心数学及算法知识点总结
ML,DL核心数学及算法知识点总结:https://mp.weixin.qq.com/s/bskyMQ2i1VMNiYKIvw_d7g
- HDU-盐水的故事
http://acm.hdu.edu.cn/showproblem.php?pid=1408 这是一道高精度问题: 在自己错了数十遍之后找到了不少规律: 首先是Output limit exceede ...
- Kafka 幂等生产者和事务生产者特性(讨论基于 kafka-python | confluent-kafka 客户端)
Kafka 提供了一个消息交付可靠性保障以及精确处理一次语义的实现.通常来说消息队列都提供多种消息语义保证 最多一次 (at most once): 消息可能会丢失,但绝不会被重复发送. 至少一次 ( ...
- 2019.11.11 模拟赛 T2 乘积求和
昨天 ych 的膜你赛,这道题我 O ( n4 ) 暴力拿了 60 pts. 这道题的做法还挺妙的,我搞了将近一天呢qwq 题解 60 pts 根据题目给出的式子,四层 for 循环暴力枚举统计答案即 ...
- GO语言测试
Go语言的测试技术是相对低级的.它依赖一个 go test 测试命令和一组按照约定方式编写的 测试函数,测试命令可以运行这些测试函数.编写相对轻量级的纯测试代码是有效的,而且它很容易延伸到基准测试和示 ...
- 实现本地des和aes 解密的工具
<?php $raw = file_get_contents('php://input'); if(!empty($raw)) { parse_str($raw);//解析到当前作用域 if ( ...
- 其他系列 | charles抓取https中出现unknow【转载】
原文:https://www.cnblogs.com/aeolian/p/9249185.html http正常抓包,https则出现unknown 1.安装证书 Help->SSL Proxy ...
- https://lug.ustc.edu.cn/wiki/user/boj/linkers-and-loaders
https://lug.ustc.edu.cn/wiki/user/boj/linkers-and-loaders 程序员的自我修养——链接.装载与库