Skip to content

Commit 47f249d

Browse files
Merge pull request algorithm001#701 from tolookme/master
【078-week4】作业提交
2 parents 0e59909 + f9bb1b5 commit 47f249d

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Week_04/id_78/LeetCode_455_78.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
int findContentChildren(vector<int>& g, vector<int>& s) {
4+
5+
sort(g.begin(),g.end());
6+
sort(s.begin(),s.end());
7+
8+
int i = 0;
9+
int j = 0;
10+
int count = 0;
11+
12+
while(i < g.size() && j < s.size()) {
13+
if(g[i] <= s[j]) {
14+
i++;
15+
count++;
16+
}
17+
j++;
18+
}
19+
20+
return count;
21+
}
22+
};
23+

Week_04/id_78/LeetCode_746_78.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
int minCostClimbingStairs(vector<int>& cost) {
4+
int len = cost.size();
5+
6+
if (len <= 2) {
7+
return std::min(cost[0], cost[1]);
8+
}
9+
10+
int step[1001];
11+
step[0] = 0;
12+
step[1] = 0;
13+
for(int i = 2; i <= len; i++){
14+
step[i] = std::min(step[i-2] + cost[i-2], step[i-1] + cost[i-1]);
15+
}
16+
17+
return step[len];
18+
}
19+
};
20+

0 commit comments

Comments
 (0)