Skip to content

Commit f133f3e

Browse files
add Solution 0075 [golang]
1 parent 6ec759e commit f133f3e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

solution/0075.Sort Colors/Solution.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @lc app=leetcode.cn id=75 lang=golang
3+
* 87/87 cases passed (4 ms), memory usage 2.4 MB
4+
*/
5+
func sortColors(nums []int) {
6+
finish0 := -1 // 元素1结束的位置
7+
start2 := len(nums) // 元素2开始的位置
8+
for i := 0; i < start2; {
9+
if nums[i] == 0 {
10+
finish0++
11+
nums[i], nums[finish0] = nums[finish0], 0
12+
i++
13+
} else if nums[i] == 2 {
14+
start2--
15+
nums[i], nums[start2] = nums[start2], 2
16+
} else {
17+
i++
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)