class Solution {
public:
string nextClosestTime(string time) {
string hour, minute;
string temp = ""; // to store temp results when parsing the input
for (char c: time){
if (c != ':')
temp.push_back(c);
else {
// encountered our first ":"
hour = temp;
temp = "";
}
}
minute = temp;
// now parsing hour and minute into "time from zero"
int minute_num = 0;
for (char c : minute){
minute_num = minute_num * 10 + (c - '0');
}
int hour_num = 0;
for (char c : hour){
hour_num = hour_num * 10 + (c - '0');
}
int time_from_zero = hour_num * 60 + minute_num;
}
};
To be finished.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.