본문 바로가기

IT/코딩테스트

[Leetcode] 905. Sort Array By Parity

728x90

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

class Solution:
    def sortArrayByParity(self, nums: List[int]) -> List[int]:
        result = []
        for i in nums:
            if i % 2 == 0:
                result.insert(0, i)
            else:
                result.append(i)
        return result
728x90