프로그래머스 120909 제곱수 판별하기

1 개요[ | ]

프로그래머스 120909 제곱수 판별하기

2 C++[ | ]

#include <string>
#include <vector>

using namespace std;

int solution(int n) {
    int square;
    for(int i=1; ;i++) {
        square = i*i;
        if(square == n) {
            return 1;
        }
        if(square > n) {
            break;
        }
    }
    return 2;
}
#include <cmath>
using namespace std;

int solution(int n) {
    int x = sqrt(n);
    return x*x==n ? 1 : 2;
}