题目如下:

解题思路:本题和【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. 阿里云code下载代码和更新代码

    1- 本地新建一个文件夹,进入文件夹下面右击打开git 2- Git init初始化一个.git文件夹 3- Git clone git@code.aliyun.com:username/space- ...

  2. womenzijide_jiafenxiang

    <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...

  3. Docker 里面新建mysql 容器

    1.获取MySQL镜像, a.直接从docker hub 下载docker镜像 docker pull +镜像名称 b.从别的项目上把镜像export出来 dockr load  i + 镜像的TAR ...

  4. swiper在vue中的用法

    首先通过npm i vue-awesome-swiper --save 来在vue中下载插件 然后再main.js中引入 require('swiper/dist/css/swiper.css')im ...

  5. idhttpserver 下载文件

    procedure TForm30.IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AR ...

  6. delphi 手势 识别 哈哈

    本例尝试在 OnGesture 事件中响应 sgLeft.sgRight 手势; 操作步骤: 1.加 TGestureManager 控件如窗体: GestureManager1; 2.设置窗体属性 ...

  7. JS 创建动态表格练习

    创建动态表格 1.1 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...

  8. Go-Mutex互斥量

    先来看一段go1.12.5中Mutex的源码: // Copyright 2009 The Go Authors. All rights reserved. // Use of this source ...

  9. Java中的基本类型和包装类型区别

    首先看一下几个测试题,验证一下java中对基本类型和包装类型的理解,看看最后输出的答案对不对,答案在这篇博客中哦: // 第一题: 基本类型和包装类型 int a = 100; Integer b = ...

  10. 面向JVM的应用程序的项目结构

    对于Maven所用的项目结构,称为Maven标准的目录结构,不包含git 一.一个典型的源代码结构: / [project-name] README.txt LICENSE.txt pom.xml / ...