i is odd, let nums[i] > mums[i - 1]. When
i is even, let nums[i] < nums[i - 1]. Use
y to reduce number of reads.
def wiggleSort(self, nums): for i in range(1, len(nums)): x, y = nums[i - 1], nums[i] if (i & 1) ^ (x < y): nums[i - 1], nums[i] = y, x
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.