1
class Solution {
2
public:
3
string reformatDate(string date) {
4
// easiest way to get index with O(1)
5
unordered_map<string, string> months = {
6
{"Jan", "01"}, {"Feb", "02"}, {"Mar", "03"}, {"Apr", "04"}, {"May", "05"}, {"Jun", "06"},
7
{"Jul", "07"}, {"Aug", "08"}, {"Sep", "09"}, {"Oct", "10"}, {"Nov", "11"}, {"Dec", "12"}};
8
istringstream s(date);
9
// get day
10
string day;
11
s >> day;
12
day.pop_back();
13
day.pop_back();
14
if (day.size() == 1) day = "0" + day;
15
// get month
16
string month;
17
s >> month;
18
// get year
19
string year;
20
s >> year;
21
return year + "-" + months[month] + "-" + day;
22
}
23
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0