问题描述
解题思路
模拟+贪心
代码
class Solution {
public:
string maximumTime(string time) {
string res;
// 先考虑小时
if (time[0] == '?') {
if (time[1] == '?')
res += "23";
else {
if (time[1] >= '4') {
res.push_back('1');
res.push_back(time[1]);
} else {
res.push_back('2');
res.push_back(time[1]);
}
}
} else {
if (time[1] == '?') {
if (time[0] == '2') {
res.push_back(time[0]);
res.push_back('3');
} else {
res.push_back(time[0]);
res.push_back('9');
}
} else {
res.push_back(time[0]);
res.push_back(time[1]);
}
}
res.push_back(time[2]);
// 再考虑分钟
if (time[3] == '?') {
if (time[4] == '?')
res += "59";
else {
res.push_back('5');
res.push_back(time[4]);
}
} else {
if (time[4] == '?') {
res.push_back(time[3]);
res.push_back('9');
} else {
res.push_back(time[3]);
res.push_back(time[4]);
}
}
return res;
}
};
标签:digits,replacing,res,back,1736,time,push,else
From: https://www.cnblogs.com/zwyyy456/p/17093703.html