imashutosh51

Wiggle sort II

Oct 8th, 2022 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. class Solution:
  2.     def wiggleSort(self, nums):
  3.         if len(nums) == 1:
  4.             return
  5.         arr = nums[:]
  6.         arr.sort()
  7.  
  8.         i = len(arr) - 1
  9.         k = 1
  10.         while i >= 0:
  11.             nums[k] = arr[i]
  12.             k += 2
  13.             if k >= len(nums):
  14.                 k = 0
  15.             i -= 1
Advertisement
Add Comment
Please, Sign In to add comment