728x90
def solution(n):
    return 1 if (n ** 0.5) % 1 == 0 else 2
  • 이번 문제는 n ** (1/2)가 제곱근이라는 것과, 숫자를 1로 나눴을 때 나머지가 0이면 정수라는 것만 인지한다면 쉽게 해결할 수 있는 문제였다.
def solution(n):
    return 1 if (n ** 0.5).is_integer() else 2

is_integer() => 정수 판별 함수

 

728x90

+ Recent posts