旅行这一周每天记了一个气温。写 hottest(temps),返回最高的那个。至少有一天,气温可能是负的。
hottest({21, 25, 19})→25hottest({18, 18, 22, 20})→22int hottest(const vector<int> &temps)#include <vector>
using namespace std;
int hottest(const vector<int> &temps) {
int best = temps[0];
for (int t : temps) {
// 在这里写:t 比 best 高,就换成 t
}
return best;
}
写好了先点「运行」试试示例,没问题再点「提交」。