—Easy

https://leetcode.com/problems/sort-array-by-parity/

Leetcode-905. 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

相关文章:

  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
  • 2021-06-19
  • 2021-08-19
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-02
  • 2021-07-22
  • 2021-08-06
  • 2021-11-17
  • 2021-07-04
  • 2021-05-10
  • 2021-08-31
相关资源
相似解决方案