Skip to content

Commit 9303baa

Browse files
authored
Add 정수-제곱근-판별.js
1 parent a9fa430 commit 9303baa

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

level-1/정수-제곱근-판별.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ function solution(n) {
2929
if (s ** 2 === n) return ((s+1) ** 2)
3030

3131
return -1;
32-
}
32+
}
33+
34+
//정답 5 - yongchanson
35+
function solution(n) {
36+
const sqrt = Math.sqrt(n);
37+
//sqrt % 1 == 0 이면 양의정수, -0이면 음의정수
38+
return sqrt % 1 == 0 ? (sqrt + 1) ** 2 : -1;
39+
}

0 commit comments

Comments
 (0)