[Programmers] #181937 - n의 배수 [Java][C++][Python]
[Programmers] #181937 - n의 배수 [Java][C++][Python]
1. 아이디어
num이 $n$의 배수라는 것은 num을 $n$으로 나눈 나머지가 0이라는 뜻이므로, 나머지만 확인하면 된다.
2. 코드
풀이 [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.