파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 5. 2. 23:45

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

 

Sort Array By Parity - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

문제가 너무 쉬워서 문제 풀고 나서 해설 봄.
좀 더 간단(혹은 간편)한 해결책이 있으면 했는데 잘 안나오네..

class Solution:
    def sortArrayByParity(self, nums: List[int]) -> List[int]:
        even, odd = list(), list()
        for num in nums:
            if num % 2 == 0:
                even.append(num)
                continue
            odd.append(num)
        return even + odd
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.05.04
Today's Challenge  (0) 2022.05.03
Today's Challenge  (0) 2022.05.01
Today's Challenge  (0) 2022.04.30
Today's Challenge  (0) 2022.04.29
Comments