본문 바로가기
CodeSignal/Arcade

CodeSignal [53/60] validTime

by 벤진[Benzene] 2020. 5. 28.

Problem:

Check if the given string is a correct time representation of the 24-hour clock.

 

Example

  • For time = "13:58", the output should be
    validTime(time) = true;
  • For time = "25:51", the output should be
    validTime(time) = false;
  • For time = "02:76", the output should be
    validTime(time) = false.

-Summary-

1. Check if 'HH' part and 'MM' part is valid (Valid only if 'HH' is between 0 to 23 and 'MM' is between 0 to 59)

 

사람들이 쓴 답을 보니, .split() 과 map() 함수를 이용하면 조금 더 간편하게 코드를 짤수 있었다.

 

def validTime(time):
    h,m=map(int,time.split(":"))
    return 0<=h<24 and 0<=m<60

 

모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]

https://codesignal.com/

'CodeSignal > Arcade' 카테고리의 다른 글

CodeSignal [55/60] differentSquares  (0) 2020.05.28
CodeSignal [54/60] sumUpNumbers  (0) 2020.05.28
CodeSignal [52/60] longestWord  (0) 2020.05.28
CodeSignal [51/60] deleteDigit  (0) 2020.05.28
CodeSignal [50/60] chessKnight  (0) 2020.05.28

댓글