[문제] You might know some pretty large perfect squares. But what about the NEXT one?
Complete the findNextSquare method that finds the next integral perfect square after the one passed as a parameter. Recall that an integral perfect square is an integer n such that sqrt(n) is also an integer.
If the parameter is itself not a perfect square, than -1 should be returned. You may assume the parameter is positive.
Examples:
findNextSquare(121) --> returns 144
findNextSquare(625) --> returns 676
findNextSquare(114) --> returns -1 since 114 is not a perfect
제곱수 : 2 * 2 일때 4
제곱근 : 2 * 2 일때 2
Math.sqrt(x) 제곱근 구하는 내장함수 4를 넣으면 2가 나오는 것.
출처: https://im-developer.tistory.com/34?category=831367 [Code Playground]
'알고리즘' 카테고리의 다른 글
JS 단어를 입력받아 짝수는 대문자, 홀수는 소문자로 변환 (0) | 2020.08.26 |
---|---|
JS 삼각형인지 확인하기 (0) | 2020.08.26 |
JS 카드번호 마지막 4글자 빼고 #으로 변환 (0) | 2020.08.26 |
JS 특정 문자를 공백으로 치환 (0) | 2020.08.26 |
JS 입력받은 단어중 가장 짧은 단어의 길이값 구하기 (0) | 2020.08.26 |