-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwiggle_sort_ii.go
48 lines (42 loc) · 943 Bytes
/
wiggle_sort_ii.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package leetcode
import (
"sort"
)
func wiggleSort(nums []int) {
sort.Ints(nums)
temp := make([]int, len(nums))
for i := 0; i < len(nums); i++ {
temp[i] = nums[i]
}
j := len(nums) - 1
for i := 1; i < len(nums); i, j = i+2, j-1 {
nums[i] = temp[j]
}
for i := 0; i < len(nums); i, j = i+2, j-1 {
nums[i] = temp[j]
}
}
// func wiggleSort(nums []int) {
// sort.Sort(Integers(nums))
// temp := make([]int, len(nums))
// for i := 0; i < len(nums); i++ {
// temp[i] = nums[i]
// }
//
// j := len(nums)-1
// for i := 1; i < len(nums); i, j = i+2, j-1 {
// nums[i] = temp[j]
// }
//
// for i := 0; i < len(nums); i, j = i+2, j-1 {
// nums[i] = temp[j]
// }
//
//
// }
//
// type Integers []int;
//
// func (x Integers) Len() int {return len(x)}
// func (x Integers) Less(i, j int) bool {return x[i] < x[j]}
// func (x Integers) Swap(i, j int) {x[i], x[j] = x[j], x[i]}