728x90
SMALL

public class Solution {
    public long solution(long n) {
        long answer = -1;
        
        for(long i = 0;i*i<=n;i++) // 루트 n까지 for문을 돌려서 
        {
            if(n == i*i)
            {
                answer = (i+1)*(i+1);
            }
        }

        return answer;
    }
}

 

///

 

using System;

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

        var sqrt = Math.Sqrt(n);

        if (sqrt % 1.0 != 0)
            return -1;

        answer = (long)sqrt;

        answer += 1;
        answer *= answer;

        return answer;
    }
}
728x90

설정

트랙백

댓글