[Programmers] 정수 제곱근 판별

이상혁·2023년 5월 11일
0

Programmers

목록 보기
12/18

문제 설명

임의의 양의 정수 n에 대해, n이 어떤 양의 정수 x의 제곱인지 아닌지 판단하려 합니다.
n이 양의 정수 x의 제곱이라면 x+1의 제곱을 리턴하고, n이 양의 정수 x의 제곱이 아니라면 -1을 리턴하는 함수를 완성하세요.

solution.js

function solution(n) {
    return Number.isInteger(Math.sqrt(n)) ? Math.pow(Math.sqrt(n) + 1, 2) : -1;
}
profile
l22coder

0개의 댓글

Powered by GraphCDN, the GraphQL CDN