—Easy
https://leetcode.com/problems/sort-array-by-parity/
Code:
class Solution: def sortArrayByParity(self, A ): ans_ls_even = [] ans_ls_odd = [] for elt in A: if elt%2 == 0: ans_ls_even.append(elt) else: ans_ls_odd.append(elt) ans_ls = ans_ls_even + ans_ls_odd return ans_ls # s = Solution() # print(s.sortArrayByParity([3,1,2,4]))
思路:
1.Parity