旅行這一週每天記了一個氣溫。寫 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;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。