정수 제곱근 판별

han.user();·2023년 4월 12일
0

프로그래머스

목록 보기
63/87
post-thumbnail

class Solution {
    public long solution(long n) {
        long answer = 0;

        double sqrt1 = Math.sqrt(n);
        int sqrt2 = (int) Math.sqrt(n);

        if(sqrt1 == sqrt2){
            return (long) ((Math.sqrt(n) + 1) * (Math.sqrt(n) + 1));
        } else {
            return -1;
        }
    }
}
profile
I'm still hungry.

0개의 댓글