Skip to content

Commit 3c31933

Browse files
author
pengliheng
committed
finish: 66 and 88
1 parent 1061172 commit 3c31933

File tree

11 files changed

+301
-2
lines changed

11 files changed

+301
-2
lines changed

coverage.txt

+26
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,13 @@ www/leetcode/kit/31.NextPermutation/main.go:12.13,16.4 3 1
349349
www/leetcode/kit/31.NextPermutation/main.go:20.27,22.3 1 3
350350
www/leetcode/kit/31.NextPermutation/main.go:24.12,28.3 3 3
351351
mode: atomic
352+
www/leetcode/kit/35.SearchInsertPosition/main.go:3.47,4.22 1 4
353+
www/leetcode/kit/35.SearchInsertPosition/main.go:7.2,7.33 1 3
354+
www/leetcode/kit/35.SearchInsertPosition/main.go:12.2,12.18 1 1
355+
www/leetcode/kit/35.SearchInsertPosition/main.go:4.22,6.3 1 1
356+
www/leetcode/kit/35.SearchInsertPosition/main.go:7.33,8.24 1 9
357+
www/leetcode/kit/35.SearchInsertPosition/main.go:8.24,10.4 1 2
358+
mode: atomic
352359
www/leetcode/kit/4.FindMedianSortedArrays/main.go:3.63,5.34 2 4
353360
www/leetcode/kit/4.FindMedianSortedArrays/main.go:12.2,12.23 1 4
354361
www/leetcode/kit/4.FindMedianSortedArrays/main.go:5.34,6.37 1 11
@@ -387,6 +394,19 @@ www/leetcode/kit/6.ZigZagConversion/main.go:19.50,21.36 2 9
387394
www/leetcode/kit/6.ZigZagConversion/main.go:21.36,23.5 1 7
388395
www/leetcode/kit/6.ZigZagConversion/main.go:26.57,28.3 1 5
389396
mode: atomic
397+
www/leetcode/kit/66.PlusOne/main.go:5.34,7.40 2 2
398+
www/leetcode/kit/66.PlusOne/main.go:33.2,33.15 1 1
399+
www/leetcode/kit/66.PlusOne/main.go:7.40,10.15 1 4
400+
www/leetcode/kit/66.PlusOne/main.go:19.3,19.25 1 4
401+
www/leetcode/kit/66.PlusOne/main.go:28.3,28.25 1 4
402+
www/leetcode/kit/66.PlusOne/main.go:10.15,11.22 1 0
403+
www/leetcode/kit/66.PlusOne/main.go:11.22,13.5 1 0
404+
www/leetcode/kit/66.PlusOne/main.go:13.10,16.5 2 0
405+
www/leetcode/kit/66.PlusOne/main.go:19.25,20.34 1 2
406+
www/leetcode/kit/66.PlusOne/main.go:20.34,23.5 2 1
407+
www/leetcode/kit/66.PlusOne/main.go:23.10,25.5 1 1
408+
www/leetcode/kit/66.PlusOne/main.go:28.25,31.4 2 1
409+
mode: atomic
390410
www/leetcode/kit/7.ReverseInteger/main.go:7.25,10.11 3 7
391411
www/leetcode/kit/7.ReverseInteger/main.go:14.2,14.12 1 7
392412
www/leetcode/kit/7.ReverseInteger/main.go:19.2,20.49 2 7
@@ -411,6 +431,12 @@ www/leetcode/kit/8.StringToInteger/main.go:40.2,40.16 1 9
411431
www/leetcode/kit/8.StringToInteger/main.go:34.29,36.3 1 1
412432
www/leetcode/kit/8.StringToInteger/main.go:37.29,39.3 1 1
413433
mode: atomic
434+
www/leetcode/kit/88.MergeSortedArray/main.go:3.58,6.39 2 3
435+
www/leetcode/kit/88.MergeSortedArray/main.go:13.2,13.14 1 3
436+
www/leetcode/kit/88.MergeSortedArray/main.go:6.39,7.43 1 10
437+
www/leetcode/kit/88.MergeSortedArray/main.go:7.43,8.34 1 30
438+
www/leetcode/kit/88.MergeSortedArray/main.go:8.34,10.14 1 10
439+
mode: atomic
414440
www/leetcode/kit/9.PalindromeNumber/main.go:7.31,9.20 2 2
415441
www/leetcode/kit/9.PalindromeNumber/main.go:14.2,14.13 1 1
416442
www/leetcode/kit/9.PalindromeNumber/main.go:9.20,10.49 1 4

interview.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
### 采访一位刷了1000道leetcode的[大佬](https://github.com/aQuaYi/LeetCode-in-Go)
2-
```
1+
# 采访一位刷了 1000 道 leetcode 的[大佬](https://github.com/aQuaYi/LeetCode-in-Go)
2+
3+
```bash
34
ali peng, [16.02.19 15:34]
45
大佬您好, 看到您用golang的刷题记录, 感觉真的很棒,特地来电报膜拜一下
56

@@ -29,4 +30,5 @@ ali peng, [18.02.19 22:53]
2930
```
3031

3132
### 结论
33+
3234
刷题能极大地提高编码能力

kit/35.SearchInsertPosition/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# [35. Search Insert Position](https://leetcode.com/problems/search-insert-position/)
2+
3+
## 2019/04/24
4+
5+
### 题目 💗[easy]

kit/35.SearchInsertPosition/main.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package searchInsert
2+
3+
func searchInsert(nums []int, target int) int {
4+
if target < nums[0] {
5+
return 0
6+
}
7+
for i := 0; i < len(nums); i++ {
8+
if nums[i] >= target {
9+
return i
10+
}
11+
}
12+
return len(nums)
13+
}
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package searchInsert
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
type para struct {
10+
one []int
11+
two int
12+
}
13+
14+
type ans struct {
15+
one int
16+
}
17+
18+
type question struct {
19+
p para
20+
a ans
21+
}
22+
23+
func Test_OK(t *testing.T) {
24+
ast := assert.New(t)
25+
26+
qs := []question{
27+
question{
28+
p: para{
29+
one: []int{1, 3, 5, 6},
30+
two: 5,
31+
},
32+
a: ans{
33+
one: 2,
34+
},
35+
},
36+
question{
37+
p: para{
38+
one: []int{1, 3, 5, 6},
39+
two: 2,
40+
},
41+
a: ans{
42+
one: 1,
43+
},
44+
},
45+
question{
46+
p: para{
47+
one: []int{1, 3, 5, 6},
48+
two: 7,
49+
},
50+
a: ans{
51+
one: 4,
52+
},
53+
},
54+
question{
55+
p: para{
56+
one: []int{1, 3, 5, 6},
57+
two: 0,
58+
},
59+
a: ans{
60+
one: 0,
61+
},
62+
},
63+
}
64+
65+
for _, q := range qs {
66+
a, p := q.a, q.p
67+
ast.Equal(a.one, searchInsert(p.one, p.two), "输入:%v", p)
68+
}
69+
70+
// ast.Panics(func() { longestPalindrome([]int{}, []int{}) }, "对空切片求中位数,却没有panic")
71+
72+
}

kit/66.PlusOne/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# [66. Plus One](https://leetcode-cn.com/problems/plus-one/submissions/)
2+
3+
## 2019/04/25
4+
5+
### 题目 💗[easy]

kit/66.PlusOne/main.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package plusOne
2+
3+
// [1,2,9]
4+
// [1,3,0]
5+
func plusOne(digits []int) []int {
6+
addLevel := false
7+
for i := len(digits) - 1; i >= 0; i-- {
8+
9+
// 如果需要进位
10+
if addLevel {
11+
if digits[i] == 9 {
12+
digits[i] = 0
13+
} else {
14+
digits[i]++
15+
addLevel = false
16+
}
17+
}
18+
// 首位
19+
if i == len(digits)-1 {
20+
if digits[len(digits)-1] == 9 {
21+
digits[len(digits)-1] = 0
22+
addLevel = true
23+
} else {
24+
digits[len(digits)-1]++
25+
}
26+
}
27+
// 如果是最后一位 , 但是 addLevel == true
28+
if addLevel && i == 0 {
29+
digits = append([]int{1}, digits...)
30+
return digits
31+
}
32+
}
33+
return digits
34+
}

kit/66.PlusOne/main_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package plusOne
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
type para struct {
10+
one []int
11+
two int
12+
}
13+
14+
type ans struct {
15+
one []int
16+
}
17+
18+
type question struct {
19+
p para
20+
a ans
21+
}
22+
23+
func Test_OK(t *testing.T) {
24+
ast := assert.New(t)
25+
26+
qs := []question{
27+
question{
28+
p: para{
29+
one: []int{1, 2, 4},
30+
},
31+
a: ans{
32+
one: []int{1, 2, 5},
33+
},
34+
},
35+
question{
36+
p: para{
37+
one: []int{9},
38+
},
39+
a: ans{
40+
one: []int{1, 0},
41+
},
42+
},
43+
}
44+
45+
for _, q := range qs {
46+
a, p := q.a, q.p
47+
ast.Equal(a.one, plusOne(p.one), "输入:%v", p)
48+
}
49+
50+
// ast.Panics(func() { longestPalindrome([]int{}, []int{}) }, "对空切片求中位数,却没有panic")
51+
52+
}

kit/88.MergeSortedArray/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# [88. Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/)
2+
3+
## 2019/04/25
4+
5+
### 题目 💗[easy]

kit/88.MergeSortedArray/main.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package merge
2+
3+
func merge(nums1 []int, m int, nums2 []int, n int) []int {
4+
nums1 = append(nums1[:m], nums2[:n]...)
5+
6+
for i := 0; i < len(nums1)-1; i++ {
7+
for j := i+1; j < len(nums1); j++ {
8+
if nums1[i]>nums1[j]{
9+
nums1[i],nums1[j] = nums1[j],nums1[i]
10+
}
11+
}
12+
}
13+
return nums1
14+
}

kit/88.MergeSortedArray/main_test.go

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package merge
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
type para struct {
10+
one []int
11+
two int
12+
three []int
13+
four int
14+
}
15+
16+
type ans struct {
17+
one []int
18+
}
19+
20+
type question struct {
21+
p para
22+
a ans
23+
}
24+
25+
func Test_OK(t *testing.T) {
26+
ast := assert.New(t)
27+
28+
qs := []question{
29+
question{
30+
p: para{
31+
one: []int{4, 5, 6, 0, 0, 0},
32+
two: 3,
33+
three: []int{1, 2, 3},
34+
four: 3,
35+
},
36+
a: ans{
37+
one: []int{1, 2, 3, 4, 5, 6},
38+
},
39+
},
40+
question{
41+
p: para{
42+
one: []int{1, 2, 3, 0, 0, 0},
43+
two: 3,
44+
three: []int{2, 5, 6},
45+
four: 3,
46+
},
47+
a: ans{
48+
one: []int{1, 2, 2, 3, 5, 6},
49+
},
50+
},
51+
question{
52+
p: para{
53+
one: []int{1},
54+
two: 1,
55+
three: []int{1},
56+
four: 0,
57+
},
58+
a: ans{
59+
one: []int{1},
60+
},
61+
},
62+
}
63+
64+
for _, q := range qs {
65+
a, p := q.a, q.p
66+
ast.Equal(a.one, merge(p.one, p.two, p.three, p.four), "输入:%v", p)
67+
}
68+
69+
// ast.Panics(func() { longestPalindrome([]int{}, []int{}) }, "对空切片求中位数,却没有panic")
70+
71+
}

0 commit comments

Comments
 (0)