728x90
https://leetcode.com/problems/sort-array-by-parity-ii/
class Solution:
def sortArrayByParityII(self, nums: List[int]) -> List[int]:
result = []
even_index = 0
odd_index = 1
for i in nums:
if i % 2 == 0:
result.insert(even_index, i)
even_index += 2
else:
result.insert(odd_index, i)
odd_index += 2
return result
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 941. Valid Mountain Array (0) | 2023.08.28 |
---|---|
[Leetcode] 1299. Replace Elements with Greatest Element on Right Side (0) | 2023.08.26 |
[Leetcode] 905. Sort Array By Parity (0) | 2023.08.26 |
[Leetcode] 620. Not Boring Movies (0) | 2023.08.25 |
[Leetcode] 26. Remove Duplicates from Sorted Array (0) | 2023.08.24 |