Post

[Programmers] #181937 - n의 배수 [Java][C++][Python]

[Programmers] #181937 - n의 배수 [Java][C++][Python]

문제 링크


1. 아이디어

정수 num이 n의 배수인지 판별하는 문제로 num을 n으로 나눈 나머지가 0이면 배수인 것을 활용하면 된다.


2. 복잡도

접근시간공간
풀이$O(1)$$O(1)$

3. 코드

풀이 [Java][C++][Python]

1
2
3
4
5
class Solution {
    public int solution(int num, int n) {
        return num % n == 0 ? 1 : 0;
    }
}
1
2
3
4
5
6
#include <bits/stdc++.h>
using namespace std;

int solution(int num, int n) {
    return num % n == 0;
}
1
2
def solution(num, n):
    return int(num % n == 0)

This post is licensed under CC BY 4.0 by the author.