<jupyter_start><jupyter_text>说明：    给定一个非负整数数组A，返回一个数组，该数组包含A的所有偶数元素，后跟A的所有奇数元素。    您可以返回满足此条件的任何答案数组。    Example 1:    Input: [3,1,2,4]    Output: [2,4,3,1]    The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted. Note:    1、1 <= A.length <= 5000    2、0 <= A[i] <= 5000<jupyter_code>class Solution:
    def sortArrayByParity(self, A: List[int]) -> List[int]:
        i, j = 0, len(A) - 1
        while i < j:
            # A[i] 是奇数，A[j] 是偶数就 swap
            if A[i] % 2 == 1 and A[j] % 2 == 0:
                A[i], A[j] = A[j], A[i]
            
            if A[i] % 2 == 0:
                i += 1
            if A[j] % 2 == 1:
                j -= 1
        return A
class Solution:
    def sortArrayByParity(self, A: List[int]) -> List[int]:
        even_num = []
        odd_num = []
        for a in A:
            if a % 2 == 0:
                even_num.append(a)
            else:
                odd_num.append(a)
        even_num.extend(odd_num)
        return even_num<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15354713313896987, 'fraction_numerical': 0.0456754130223518, 'mean_word_length': 1.641025641025641, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '237502', 'license': 'Apache-2.0', 'n_tokens_mistral': 466, 'n_tokens_neox': 449, 'n_words': 93, 'path': 'Array/0924/905. Sort Array By Parity.ipynb', 'repo_name': 'YuHe0108/Leetcode', 'size': '1029'}