fbaquant / LeetCode

1 stars 0 forks source link

Sort Array By Parity #107

Open juneharold opened 3 months ago

juneharold commented 3 months ago

Create two new arrays: one with only even and other with only odd. Combine the two arrays

class Solution:
   def sortArrayByParity(self, nums: List[int]) -> List[int]:

       lst_odd = [i for i in nums if i%2 == 1]
       lst_even = [i for i in nums if i%2 == 0]

       return lst_even + lst_odd