[Programmers] 181937번 - n의 배수 [Java][C++]
[Programmers] 181937번 - n의 배수 [Java][C++]
1. 아이디어
num을 n으로 나눈 나머지가 0인지만 확인해주면 된다.
2. 복잡도
| 시간복잡도 | 공간복잡도 |
|---|---|
| $O(1)$ | $O(1)$ |
3. 코드
풀이 [Java][C++]
1
2
3
4
5
class Solution {
public int solution(int num, int n) {
return num % n == 0 ? 1 : 0;
}
}
1
2
3
int solution(int num, int n) {
return num % n == 0;
}
This post is licensed under CC BY 4.0 by the author.