2164. Sort Even and Odd Indices Independently

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2164

class Solution:
    def sortEvenOdd(self, nums: List[int]) -> List[int]:
        a = sorted(nums[::2])
        b = sorted(nums[1::2], reverse=True)
        nums[::2] = a
        nums[1::2] = b
        return nums