class Solution:
def sortArrayByParity(self, A):
"""
:type A: List[int]
:rtype: List[int]
"""
a=[]
b=[]
for i in A:
if i % 2 ==0 :
a.append(i)
else:
b.append(i)
return a+b
leetcode - 905 - 按奇偶排序数组
最新推荐文章于 2022-04-28 10:41:51 发布
本文深入探讨了一种基于数组元素奇偶性的排序算法实现。通过将数组中的所有偶数元素放置在前部,所有奇数元素放置在后部,该算法提供了一种直观且高效的排序方法。代码示例清晰展示了如何遍历数组并根据元素的奇偶性进行分类。
1191

被折叠的 条评论
为什么被折叠?



