코딩테스트 연습
025-정수 제곱근 판별
__g__
2022. 5. 17. 23:40
function solution(n) {
var answer = 0;
var root = Math.sqrt(n) // 제곱근을 root에 담음
if (root % 1 == 0) { // 제곱근을 나눴을 때 양의 정수일 때
return Math.pow(root+1, 2)
} else {
return -1 // 아니라면 -1 반환
}
}