+ 1
Your solution is not entirely correct. Perhaps that is the reason why the solution you found seems weird to you. But, in fact, it handles the special cases that you don't. For example 12:33 AM ought to translate to 00:33. What you could think of in situations that require you to verify a certain string format and splitting it into components is: regular expressions. To make things more readable, I'd advise to use variable names that say what they stand for, for example a boolean var named "is_am" or "is_morning_time". If you later write "if (is_am): ..." you know exactly what the if statement expresses.
9th Aug 2022, 3:23 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
If you are searching for a less messy solution for similar problems like these, where time or date calculations are being done. you could use the necessary libraries for it and you could save yourself some time. Here my solution: https://code.sololearn.com/cpX0tO6fFHsr/?ref=app
9th Aug 2022, 6:11 PM
YuGiMob
YuGiMob - avatar
+ 1
Still not quite. Now you have removed the case of single digit hours in the morning. E.g. 9:00 has to turn into 09:00.
9th Aug 2022, 7:32 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar