๐ฉ๐ปProgramming/Coding Test
[C#][Programmers] ์ ๊ณฑ์ ํ๋ณํ๊ธฐ
taesooya
2022. 11. 26. 21:58
์ด๋ค ์์ฐ์๋ฅผ ์ ๊ณฑํ์ ๋ ๋์ค๋ ์ ์๋ฅผ ์ ๊ณฑ์๋ผ๊ณ ํฉ๋๋ค. ์ ์ n์ด ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, n์ด ์ ๊ณฑ์๋ผ๋ฉด 1์ ์๋๋ผ๋ฉด 2๋ฅผ returnํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์.
using System;
public class Solution {
public int solution(int n) {
int answer = 0;
double tmp = Math.Sqrt((double)n);
answer = tmp % 1 == 0 ? 1 : 2;
return answer;
}
}
using System;
public class Solution {
public int solution(int n) {
int answer = Math.Sqrt(n) % 1 == 0 ? 1 : 2;
return answer;
}
}
์กฐ๊ฑด๋ฌธ์์ .....
์ ์์ธ์ง ํ๋ณ : 1๋ก ๋๋ ๋๋จธ์ง ํ์ธ