Skip to content

Commit 8288899

Browse files
Merge pull request #1681 from CodingTestStudy2/염혜정
[염혜정] Day18
2 parents 7f5ff5e + 38b0e32 commit 8288899

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// n을 각 자릿수를 더한 sum / 곱한 값인 product를 더한 값으로 나눠준다.
2+
// O(log n)
3+
4+
class Solution {
5+
public boolean checkDivisibility(int n) {
6+
int sum = 0;
7+
int product = 1;
8+
int temp = n;
9+
10+
while (temp>0) {
11+
int digit = temp % 10;
12+
sum += digit;
13+
product *= digit;
14+
temp /= 10;
15+
}
16+
17+
boolean result = n % (sum+product) == 0? true: false;
18+
return result;
19+
}
20+
}

0 commit comments

Comments
 (0)