Skip to content

Commit d6f742a

Browse files
aQuaaQua
aQua
authored and
aQua
committed
helper 修改细节
1 parent 2a8f0a9 commit d6f742a

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

Algorithms/0075.sort-colors/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# [75. Sort Colors](https://leetcode.com/problems/sort-colors/)
2+
3+
## 题目
4+
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
5+
6+
7+
8+
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
9+
10+
11+
12+
Note:
13+
You are not suppose to use the library's sort function for this problem.
14+
15+
16+
click to show follow up.
17+
18+
19+
Follow up:
20+
A rather straight forward solution is a two-pass algorithm using counting sort.
21+
First, iterate the array counting number of 0's, 1's, and 2's, then overwrite array with total number of 0's, then 1's and followed by 2's.
22+
Could you come up with an one-pass algorithm using only constant space?
23+
24+
## 解题思路
25+
26+
见程序注释
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package Problem0075
2+
3+
func sortColors(nums []int) {
4+
5+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package Problem0075
2+
3+
import (
4+
"testing"
5+
"fmt"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
type question struct {
11+
para
12+
ans
13+
}
14+
15+
// para 是参数
16+
type para struct {
17+
nums []int
18+
}
19+
20+
// ans 是答案
21+
type ans struct {
22+
one
23+
}
24+
25+
func Test_Problem0075(t *testing.T) {
26+
ast := assert.New(t)
27+
28+
qs := []question{
29+
30+
question{
31+
para{
32+
,
33+
},
34+
ans{
35+
,
36+
},
37+
},
38+
39+
// 如需多个测试,可以复制上方元素。
40+
}
41+
42+
for _, q := range qs {
43+
a, p := q.ans, q.para
44+
fmt.Printf("~~%v~~\n", p)
45+
46+
ast.Equal(a.one, sortColors(p. ), "输入:%v", p)
47+
}
48+
}

helper.v3/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func init() {
2626
if _, err := toml.DecodeFile(cfgFile, &cfg); err != nil {
2727
log.Fatalf(err.Error())
2828
}
29-
fmt.Printf("Hi, %s. \n", cfg.Login)
29+
log.Printf("Hi, %s. \n", cfg.Login)
3030
}
3131

3232
func main() {

0 commit comments

Comments
 (0)