Problem 280: Wiggle Sort

https://leetcode.com/problems/wiggle-sort/#/description

思路

https://discuss.leetcode.com/topic/57053/java-solution-with-explanation-thoughts/2

这个讲解不错!

  • 我们有四种情况

  • 也就是说,对于奇数位 (实际上是 index 为奇数, 比如 nums 里面的第二个元素),它要看看是否比上一个大,如果不是

要交换;如果是偶数位,要看它是否比上一个元素小,否则要交换。

Last updated

Was this helpful?