题目如下:

解题思路:本题和【leetcode】75. Sort Colors类似,但是没有要求在输入数组本身修改,所以难度降低了。引入一个新的数组,然后遍历输入数组,如果数组元素是是偶数,插入到新数组头部,否则追加到尾部。

代码如下:

class Solution(object):
def sortArrayByParity(self, A):
"""
:type A: List[int]
:rtype: List[int]
"""
res = []
for i in A:
if i % 2 == 0:
res.insert(0,i)
else:
res.append(i)
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_easy】905. Sort Array By Parity

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

  3. 【LeetCode】922. Sort Array By Parity II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用奇偶数组 排序 奇偶数位置变量 日期 题目地址: ...

  4. 【leetcode】922. Sort Array By Parity II

    题目如下: 解题思路:非常简单的题目,引入两个变量oddInx = 1和evenInx = 0,和与A等长的结果数组res.然后遍历A,如果A[i]为偶数,则令res[evenInx] = A[i], ...

  5. 【Leetcode_easy】922. Sort Array By Parity II

    problem 922. Sort Array By Parity II solution1: class Solution { public: vector<int> sortArray ...

  6. 【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.  ...

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

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

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

  9. 905. Sort Array By Parity - LeetCode

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

随机推荐

  1. 牛客网暑期ACM多校训练营(第五场) F - take —— 期望+树状数组+逆元

    看到一篇好的博客特意转出来观摩大佬:转:https://blog.csdn.net/greybtfly/article/details/81413526 题目大意:给n个箱子排成一排,从头到尾按顺序依 ...

  2. sql server查询结果复制出来,没有换行(存进去的数据是换行的)

    https://stackoverflow.com/questions/53115490/how-to-correctly-insert-newline-in-nvarchar The problem ...

  3. python 日期相关

    基本的日期与时间转换 问题 你需要执行简单的时间转换,比如天到秒,小时到分钟等的转换. 解决方案 为了执行不同时间单位的转换和计算,请使用 datetime 模块. 比如,为了表示一个时间段,可以创建 ...

  4. Ehcache配置项及持久化到硬盘

    EhCache 常见的配置项: cache元素的属性 name:缓存名称 maxElementsInMemory:内存中最大缓存对象数 maxElementsOnDisk:硬盘中最大缓存对象数,若是0 ...

  5. OAuth 2.0 综述

    OAuth 2.0 rfc6749 规范 OAuth 2.0 rfc6749 规范-带目录,阅读 RFC 文档的 工具 OAuth 官网 OAuth2 核心 角色 Token 类型 access to ...

  6. 【转载】Spring boot学习记录(二)-配置文件解析

    前言:本系列文章非本人原创,转自:http://tengj.top/2017/04/24/springboot0/ 正文 Spring Boot使用了一个全局的配置文件application.prop ...

  7. 【ABAP系列】SAP ABAP基础-录制BDC的MODE定义解析

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP基础-录制BDC ...

  8. Web控件中Eval()的使用

    1.使用Eval()绑定数据时使用三元运算符 <%#Eval("hg_A").ToString()=="1"?"通过":Eval(&q ...

  9. HTML5-Classlist样式操作

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 《JAVA设计模式》之中介者模式(Mediator)

    在阎宏博士的<JAVA与模式>一书中开头是这样描述调停者(Mediator)模式的: 调停者模式是对象的行为模式.调停者模式包装了一系列对象相互作用的方式,使得这些对象不必相互明显引用.从 ...