정수 제곱근 판별

l·2022년 4월 26일
0
post-thumbnail

문제

https://programmers.co.kr/learn/courses/30/lessons/12934

풀이

function solution(n) {
    let answer = 0;
    const squareRoot = Math.sqrt(n);
    const isInteger = Number.isInteger(squareRoot);
    if (isInteger) {
        answer = Math.pow(squareRoot + 1, 2);
    } else {
        answer = -1;
    }
    
    return answer;
}

0개의 댓글

관련 채용 정보