Skip to content

Commit e205cdd

Browse files
Merge pull request algorithm001#720 from JYSDeveloper/week4
103 - 第四周作业
2 parents 2afe779 + 730662f commit e205cdd

6 files changed

Lines changed: 273 additions & 1 deletion

File tree

Week_02/id_103/.idea/workspace.xml

Lines changed: 213 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Week_04/id_103/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, build with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
.idea

Week_04/id_103/NOTE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# 学习笔记
1+
# 学习笔记
2+
3+
- 169 既然一个数半数都存在,那排好序之后,一定在中间
4+
- 455 这个排序后,看每块饼干能否满足小朋友,能的话,就递增,不能就再继续,就能判断出来了,不过对小朋友的胃口和饼干要提前排序。
5+
- 746 到达当前台阶时判断下从前一个台阶过来省事,还是从前一个的前一个过来省事,一直累加到最后一个台阶完,最小值就是最省体力的。 用p1和p2表示前两个和前一个台阶所耗费的体力,一遍循环就可以了。

Week_04/id_103/leetcode_103_169.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package id_103
2+
3+
import "sort"
4+
5+
func majorityElement(nums []int) int {
6+
sort.Ints(nums)
7+
return nums[len(nums) / 2]
8+
}

Week_04/id_103/leetcode_103_455.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package id_103
2+
3+
import "sort"
4+
5+
func findContentChildren(g []int, s []int) int {
6+
sort.Ints(g)
7+
sort.Ints(s)
8+
child, cookie := 0,0
9+
for child < len(g) && cookie < len(s){
10+
if g[child] <= s[cookie]{
11+
child++
12+
}
13+
cookie++
14+
}
15+
return child
16+
}

Week_04/id_103/leetcode_103_746.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package id_103
2+
3+
func minCostClimbingStairs(cost []int) int {
4+
p1,p2 := 0,0
5+
for i := 2; i <= len(cost); i++ {
6+
p1 , p2 = p2, min(p2 + cost[i-1],p1+cost[i-2])
7+
}
8+
return p2
9+
}
10+
11+
func min(a,b int) int {
12+
if a > b{
13+
return b
14+
}else{
15+
return a
16+
}
17+
}

0 commit comments

Comments
 (0)