We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def timeConversion(s):
newS = ""
if "AM" in s and "12" in s:
newS = "00"
elif "PM" in s and "12" not in str(s[:2]):
newS = str(int(s[:2]) + 12)
else:
return s[:len(s)-2]
return newS + s[2:len(s)-2]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →
python using array slicing:
def timeConversion(s): newS = "" if "AM" in s and "12" in s: newS = "00" elif "PM" in s and "12" not in str(s[:2]): newS = str(int(s[:2]) + 12) else: return s[:len(s)-2] return newS + s[2:len(s)-2]