[나의 풀이]
import math
def solution(n): # 121이 들어오면 144가 리턴된다 .. 즉 121은 양의 정수 11
x = math.sqrt(n) # sqrt는 루트 pow는 제곱
if x % 1 == 0:
j = int(x) + 1
return pow(j, 2) # j의 2승을 의미
return -1
[다른 풀이]
def nextSqure(n):
sqrt = n ** (1/2)
if sqrt % 1 == 0:
return (sqrt + 1) ** 2
return 'no'
def nextSqure(n):
return n == int(n**.5)**2 and int(n**.5+1)**2 or 'no'
def nextSqure(n):
from math import sqrt
return "no" if sqrt(n) % 1 else (sqrt(n)+1)**2
'workSpace > ALGORITHM' 카테고리의 다른 글
[Python][sort][sorted] 정수 내림차순으로 배치하기 (0) | 2020.12.20 |
---|---|
[Python][isdigit][isalpha] 문자열 다루기 기본 (0) | 2020.12.20 |
[Python] 최대공약수와 최소공배수 (0) | 2020.12.20 |
[Python] 자릿수 더하기 (0) | 2020.12.20 |
[Python] 짝수와 홀수 (0) | 2020.12.20 |