【leetcode】905. Sort Array By Parity
题目如下:

解题思路:本题和【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的更多相关文章
- 【LeetCode】905. Sort Array By Parity 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 自定义sorted函数的cmp 日期 题目地址:h ...
- 【Leetcode_easy】905. Sort Array By Parity
problem 905. Sort Array By Parity solution1: class Solution { public: vector<int> sortArrayByP ...
- 【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】922. Sort Array By Parity II
problem 922. Sort Array By Parity II solution1: class Solution { public: vector<int> sortArray ...
- 【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】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, ...
随机推荐
- html5 figure和figcaption
figure标签和figcaption标签是html5新增的语义化标签. figure标签,html5语义化标签. 用于规定独立的流内容(图像.图表.照片.代码等等). figcaption标签,ht ...
- (转)GIS理论知识(三)之ArcGIS平台、SuperMap超图平台和开源平台
3.1.ArcGIS平台 ArcGIS为美国ESRI公司研发的产品,为用户提供一个可伸缩的,全面的GIS平台.ArcObjects包含了许多的可编程组件,从细粒度的对象(例如单个的几何对象)到粗粒度的 ...
- 设置Select下拉多选框功能,赋值与绑定问题
项目需要所以更改select为多选下拉的菜单选项. 我用的是后台直接绑定 在前台aspx页面直接写一个 <div id="dropsxs" runat="serve ...
- HDU6424 Rikka with Time Complexity
HDU6424 Rikka with Time Complexity 数学题~(真的数学题) #include <bits/stdc++.h> #define mp(_,__) make_ ...
- RDA项目debug
- NOIP 真题选讲
推荐生要凉辽 这可能是我更新的最后一篇博客 代码什么的有时间再说吧,先讲思路.(已搞定前三题代码) 首先先看一下线段覆盖题.我们有一个区间,要用线段覆盖整个区间. 这个是线段的覆盖简图.我们如何选取最 ...
- random、os、时间模块
一.random 模块 1.随机小数 random.random() #产生大于0且小于1之间的小数 random.uniform(1,3) #产生1到3之间的随机小数 2.随机整数 rand ...
- Caffe深入分析(源码)
Caffe的整体流程图: 程序入口:main() int main(int argc, char** argv) { ..... ]))(); .... } g_brew_map实现过程,首先通过 t ...
- 【ABAP系列】SAP DOI技术中I_OI_SPREADSHEET接口的使用
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP DOI技术中I_OI_S ...
- 关于Visual Studio中书签Bookmark的一些问题
VS自带一个书签功能,但是有个大问题,没有导出功能,因为这个书签是保存在工程.suo文件中,所以在移动,分享,甚至其他情况下很不方便,甚至丢失. 在你分析一个较大的开源,做了30-50个关键代码书签, ...