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, 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 解题报告的更多相关文章
- 【LeetCode】905. Sort Array By Parity 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 自定义sorted函数的cmp 日期 题目地址:h ...
- 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 ...
- [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, ...
- LeetCode 905. Sort Array By Parity 按奇偶校验排列数组
题目 Given an array A of non-negative integers, return an array consisting of all the even elements of ...
- [leetcode] 905. Sort Array By Parity [easy]
原题链接 很水的一道题,就是数组内部交换. 水题就想着减少复杂度嘛,于是学到一种交换写法. class Solution { public: vector<int> sortArrayBy ...
- 【LEETCODE】41、905. Sort Array By Parity
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 905. Sort Array By Parity - LeetCode
Question 905. Sort Array By Parity Solution 题目大意:数组排序,偶数放前,奇数在后,偶数的数之间不用管顺序,奇数的数之间也不用管顺序 思路:建两个list, ...
- 【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 C++ 解题报告
922. Sort Array By Parity II 题目描述 Given an array A of non-negative integers, half of the integers in ...
随机推荐
- idea 导入 android项目
1. 2. 主要是勾选上面选项. next next 导入即可
- Centos 6.4 安装dnsmasq
1 下载源码 wget http://www.thekelleys.org.uk/dnsmasq/dnsmasq-2.45.tar.gz cp dnsmasq-2.45.tar.gz /usr/src ...
- Hadoop2.6新增用户隔离
1.hadoop文件权限介绍 (这部分内容参考成品 https://blog.csdn.net/skywalker_only/article/details/40709447) 之前在论坛看到一个关 ...
- 图像处理滤波应用(Halcon)
1.增强对比度:halcon算子 equ_histo_image (GrayImage, ImageEquHisto) 2.空间滤波基础 滤波指接受或拒绝一定的频率分量.低通滤波器的最终效果是模糊(平 ...
- Android GIS +webservice
Android新手经典入门教程 Android开发教程(完全免费版) Android SDK v3.1.0 Android定位功能(一) Android定位功能(二) Android 百度地图开发(一 ...
- CentOS重新加载网卡报错 Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/23
最新文章:Virson's Blog 重新加载网卡时出现的错误如下: [root@vdb1 dev]# service network restart Shutting down interface ...
- Java8使用@sun.misc.Contended避免伪共享(False Sharing)
伪共享(False Sharing) Java8中用sun.misc.Contended避免伪共享(false sharing) Java8使用@sun.misc.Contended避免伪共享
- jQuery表格列宽可变,兼容firfox
本demo使用jQuery包,实现表格列宽可拖拽功能,并实现页面reset时的重新布局.使用jQuery,方便函数的调用,给要处理的表格添加id 后,直接调用$("#id").mo ...
- HTTPS与证书
HTTPS(Secure Hypertext Transfer Protocol)安全超文本传输协议它是一个安全通信通道,它基于HTTP开发,用于在客户计算机和服务器之间交换信息.它使用安全套接字层( ...
- linux log
adb shell logcat GOODIX:v *:s cat /proc/kmsg | grep "<<" ./cbootimg.sh adb shell get ...