Skip to content

Commit ac25562

Browse files
committed
Create 75. Sort Colors.swift
1 parent 5a31522 commit ac25562

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Swift/75. Sort Colors.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// 75. Sort Colors
2+
// 12 ms, 68.92%
3+
func sortColors(_ nums: inout [Int]) {
4+
var i0 = 0, i1 = 0, i2 = nums.count-1
5+
while i1 <= i2 {
6+
if nums[i1] == 2 {
7+
nums.swapAt(i1, i2)
8+
i2 -= 1
9+
} else if nums[i1] == 0 {
10+
nums.swapAt(i0, i1)
11+
i0 += 1; i1 += 1
12+
} else {
13+
i1 += 1
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)