Parse a Timestamp
Medium · rating 1100 · Strings, Implementation
Read a duration in the format HH:MM:SS (each field two digits). Print the total number of seconds.
Editorial
Parse a Timestamp converts HH:MM:SS into a total number of seconds. Split on the colons and combine: hours·3600 + minutes·60 + seconds.
h, m, s = map(int, text.split(':'))
print(h*3600 + m*60 + s)Complexity
Time: O(1). Space: O(1).
Related problems
- Caesar Cipher — Medium
- RGB to Hex Color — Easy
- Roman to Integer — Medium
- Password Strength — Medium
- URL Slug — Medium
- Reverse a String — Easy