diff --git a/lcci/10.11.Peaks and Valleys/README.md b/lcci/10.11.Peaks and Valleys/README.md index 9f3aaf7cfd4eb..2f2e92d8dc930 100644 --- a/lcci/10.11.Peaks and Valleys/README.md +++ b/lcci/10.11.Peaks and Valleys/README.md @@ -82,6 +82,22 @@ function wiggleSort(nums: number[]): void { } ``` +```swift +class Solution { + func wiggleSort(_ nums: inout [Int]) { + nums.sort() + + let n = nums.count + + for i in stride(from: 0, to: n - 1, by: 2) { + let temp = nums[i] + nums[i] = nums[i + 1] + nums[i + 1] = temp + } + } +} +``` + diff --git a/lcci/10.11.Peaks and Valleys/README_EN.md b/lcci/10.11.Peaks and Valleys/README_EN.md index 565ea89c2798a..12d7cdf7200c4 100644 --- a/lcci/10.11.Peaks and Valleys/README_EN.md +++ b/lcci/10.11.Peaks and Valleys/README_EN.md @@ -85,6 +85,22 @@ function wiggleSort(nums: number[]): void { } ``` +```swift +class Solution { + func wiggleSort(_ nums: inout [Int]) { + nums.sort() + + let n = nums.count + + for i in stride(from: 0, to: n - 1, by: 2) { + let temp = nums[i] + nums[i] = nums[i + 1] + nums[i + 1] = temp + } + } +} +``` + diff --git a/lcci/10.11.Peaks and Valleys/Solution.swift b/lcci/10.11.Peaks and Valleys/Solution.swift new file mode 100644 index 0000000000000..96fea24928059 --- /dev/null +++ b/lcci/10.11.Peaks and Valleys/Solution.swift @@ -0,0 +1,13 @@ +class Solution { + func wiggleSort(_ nums: inout [Int]) { + nums.sort() + + let n = nums.count + + for i in stride(from: 0, to: n - 1, by: 2) { + let temp = nums[i] + nums[i] = nums[i + 1] + nums[i + 1] = temp + } + } +} \ No newline at end of file