Skip to content

Commit 911f098

Browse files
authoredMay 3, 2024··
feat: add swift implementation to lcci problem: No.10.11 (#2717)
* Swift Implementation for LCCI 10.11 * style: format code and docs with prettier --------- Co-authored-by: klever34 <klever34@users.noreply.github.com>
1 parent 72997fd commit 911f098

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
 

Diff for: ‎lcci/10.11.Peaks and Valleys/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ function wiggleSort(nums: number[]): void {
8282
}
8383
```
8484

85+
```swift
86+
class Solution {
87+
func wiggleSort(_ nums: inout [Int]) {
88+
nums.sort()
89+
90+
let n = nums.count
91+
92+
for i in stride(from: 0, to: n - 1, by: 2) {
93+
let temp = nums[i]
94+
nums[i] = nums[i + 1]
95+
nums[i + 1] = temp
96+
}
97+
}
98+
}
99+
```
100+
85101
<!-- tabs:end -->
86102

87103
<!-- end -->

Diff for: ‎lcci/10.11.Peaks and Valleys/README_EN.md

+16
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ function wiggleSort(nums: number[]): void {
8585
}
8686
```
8787

88+
```swift
89+
class Solution {
90+
func wiggleSort(_ nums: inout [Int]) {
91+
nums.sort()
92+
93+
let n = nums.count
94+
95+
for i in stride(from: 0, to: n - 1, by: 2) {
96+
let temp = nums[i]
97+
nums[i] = nums[i + 1]
98+
nums[i + 1] = temp
99+
}
100+
}
101+
}
102+
```
103+
88104
<!-- tabs:end -->
89105

90106
<!-- end -->

Diff for: ‎lcci/10.11.Peaks and Valleys/Solution.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
func wiggleSort(_ nums: inout [Int]) {
3+
nums.sort()
4+
5+
let n = nums.count
6+
7+
for i in stride(from: 0, to: n - 1, by: 2) {
8+
let temp = nums[i]
9+
nums[i] = nums[i + 1]
10+
nums[i + 1] = temp
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)
Please sign in to comment.