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.
deftimeConversion(s):HMS=[int(s[0])*10+int(s[1]),int(s[3])*10+int(s[4]),int(s[6])*10+int(s[7]),]# If past Midnight, add 12ifs[8]=='P'andHMS[0]!=12:HMS[0]+=12# If past Daytime, minus 12ifs[8]=='A'andHMS[0]>=12andHMS[1]>=0:HMS[0]-=12HMS=formatNumbers(HMS)returnstr(HMS[0])+":"+str(HMS[1])+":"+str(HMS[2])defformatNumbers(arr):foriinrange(len(arr)):ifarr[i]<10:arr[i]="0"+str(arr[i])returnarr
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 →