역시 코테하면 파이썬만한 것이 없는 것 같아서 알고리즘 공부를 하면서 파이썬 공부도 하는 중이다‼️
내가 제시한 풀이 방식
def timeConversion(s):
timeZone=s[-2];
hour_str = s[:2];
hour_int = int(hour_str);
others = s[2:-2]
if timeZone=='P' and hour_int<12:
hour_int+=12;
elif timeZone=='A' and hour_int==12:
hour_int=0;
return f"{hour_int:02d}{others}"
제미나이가 말한 정석적 풀이
def timeConversion(s):
meridiem = s[-2:] # AM 또는 PM
hour = int(s[:2]) # 시간 숫자화
others = s[2:-2] # :MM:SS 부분
if meridiem == "AM":
if hour == 12:
hour = 0
else: # PM인 경우
if hour != 12:
hour += 12
return f"{hour:02d}{others}"