-
프로그래머스 - 정수 제곱근 판별 [자바]Algorithms/- 프로그래머스 2022. 2. 1. 17:48
- 문제 링크 : 정수 제곱근 판별
정답
class Solution { public long solution(long n) { long x = (long) Math.sqrt(n); if(n == (long)Math.pow(x, 2)){ return (long)Math.pow(x+1, 2); }else{ return -1L; } } }
분석
- int의 입력값의 범위 대략 21억을 알고 있는지
- java Math 라이브러리를 알고 있는지에 따라 소스 길이가 달라진다.
반응형