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.
funcconverter(sstring,formatstring)string{seperator:=":"varssstringifstrings.HasSuffix(s,format){ss=s[:len(s)-len(format)]}sl:=strings.Split(ss,seperator)firstIndexValue,err:=strconv.Atoi(sl[0])iferr!=nil{return"error"}ifformat=="AM"{iffirstIndexValue==12{sl[0]="00"finalString:=strings.Join(sl,seperator)returnfinalString}else{// it means, firstIndexValue < 12returnss}}else{// format == "PM"iffirstIndexValue==12{returnss}newVal:=firstIndexValue+12sl[0]=strconv.Itoa(newVal)finalString2:=strings.Join(sl,seperator)returnfinalString2}}functimeConversion(sstring)string{// Write your code hereifstrings.Contains(s,"AM"){returnconverter(s,"AM")}elseifstrings.Contains(s,"PM"){returnconverter(s,"PM")}return"something went wrong"}
`
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 →
GoLang code
`