Advertisement
HXXXXJ

324. Wiggle Sort II

Mar 18th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.33 KB | None | 0 0
  1.   func wiggleSort(_ nums: inout [Int]) {
  2.         var sortedNums = nums.sorted()
  3.         let n = nums.count
  4.         for i in stride(from: 1, to:n , by: 2) {
  5.             nums[i] = sortedNums.removeLast()
  6.         }
  7.        
  8.         for i in stride(from: 0, to:n , by: 2) {
  9.             nums[i] = sortedNums.removeLast()
  10.         }
  11.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement