题目要求

Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A.

You may return any answer array that satisfies this condition.

题目分析及思路

题目给出一个含有非负整数的数组A,要求返回一个数组,前面的元素都是A中的偶数,后面的元素都是A中的奇数。可以新建一个list,先遍历A一次,把偶数元素都插入到里面;再遍历A一次,这次只插入奇数元素。

python代码​

class Solution:

def sortArrayByParity(self, A):

"""

:type A: List[int]

:rtype: List[int]

"""

res = list()

for e in A:

if e % 2 == 0:

res.append(e)

for e in A:

if e % 2 == 1:

res.append(e)

return res

LeetCode 905 Sort Array By Parity 解题报告的更多相关文章

  1. 【LeetCode】905. Sort Array By Parity 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 自定义sorted函数的cmp 日期 题目地址:h ...

  2. 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 ...

  3. [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, ...

  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] 905. Sort Array By Parity [easy]

    原题链接 很水的一道题,就是数组内部交换. 水题就想着减少复杂度嘛,于是学到一种交换写法. class Solution { public: vector<int> sortArrayBy ...

  6. 【LEETCODE】41、905. Sort Array By Parity

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  7. 905. Sort Array By Parity - LeetCode

    Question 905. Sort Array By Parity Solution 题目大意:数组排序,偶数放前,奇数在后,偶数的数之间不用管顺序,奇数的数之间也不用管顺序 思路:建两个list, ...

  8. 【Leetcode_easy】905. Sort Array By Parity

    problem 905. Sort Array By Parity solution1: class Solution { public: vector<int> sortArrayByP ...

  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. css font-family常用的黑体宋体等字体中英文对照

    资料来源: https://www.cnblogs.com/EnSnail/p/6792853.html 在实现网页效果时,细节很重要,字体也不例外,CSS:font-family常用字体中英文对照如 ...

  2. 【emWin】例程十八:jpeg图片显示

    说明:1.将文件拷入SD卡内即可在指定位置绘制jpeg图片文件,不必加载到储存器.     由于jpeg格式文件显示时需要进行解压缩,耗用动态内存,iCore3所有模块受emwin缓存的限制,jpeg ...

  3. 【css】css 中文字体 unicode 对照表

    css 中文字体可以用 unicode 格式来表示,比如“宋体”可以用 \5B8B\4F53 来表示.具体参考下表: 中文名 英文名 unicode 宋体 SimSun \5B8B\4F53 黑体 S ...

  4. opencv2/nonfree/nonfree.hpp:没有那个文件或目录

    致命错误: opencv2/nonfree/nonfree.hpp:没有那个文件或目录 fatal error: opencv2/nonfree/nonfree.hpp: No such file o ...

  5. Genymotion模拟器出现INSTALL_FAILED_NO_MATCHING_ABIS 的解决办法

    下载插件: http://files.cnblogs.com/files/feijian/genymotion-arm-translation_v1.1.zip 步骤: 将模拟器运行起来,然后将下载好 ...

  6. Java知多少(16)StringBuffer与StringBuider

    String 的值是不可变的,每次对String的操作都会生成新的String对象,不仅效率低,而且耗费大量内存空间. StringBuffer类和String类一样,也用来表示字符串,但是Strin ...

  7. java二叉树字典查询(qq 928900200)

    This assignment will help you practice and understand better the Binary Tree and Binary Search Tree ...

  8. 错误:OSError: [Errno 1] Operation not permitted: 'lib/python/six-1.4.1-py2.7.egg-info'

    解决办法: $ $ pip install mock --ignore-installed six --user 问题:安装mock时报错: (venv)➜ test git:(master) pip ...

  9. SpringBoot整合Mail

    前言 SpringBoot实现邮件功能是非常的方便快捷的,因为SpringBoot默认有starter实现了Mail. 发送邮件应该是网站的必备功能之一,什么注册验证,忘记密码或者是给用户发送营销信息 ...

  10. [PHP] 06 - Security: Error, Exception and Filter

    前言 Ref: PHP 发送电子邮件 Ref: PHP Secure E-mails PHP发邮件部分在此系列中略. 这里展开”安全“相关的部分. 有啥区别?  Ref: PHP异常与错误处理机制 P ...