Skip to content

Commit e3c901c

Browse files
solves #2520: Count the Digits That Divide a Number in java
1 parent 43be834 commit e3c901c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@
791791
| 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings) | [![Java](assets/java.png)](src/CountPairsOfSimilarStrings.java) | |
792792
| 2511 | [Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured) | [![Java](assets/java.png)](src/MaximumEnemyFortsThatCanBeCaptured.java) | |
793793
| 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array) | [![Java](assets/java.png)](src/ShortestDistanceToTargetStringInACircularArray.java) | |
794-
| 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | | |
794+
| 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number) | [![Java](assets/java.png)](src/CountTheDigitsThatDivideANumber.java) | |
795795
| 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria) | | |
796796
| 2529 | [Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) | | |
797797
| 2535 | [Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array) | | |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://leetcode.com/problems/count-the-digits-that-divide-a-number
2+
// T: O(log(N))
3+
// S: O(1)
4+
5+
public class CountTheDigitsThatDivideANumber {
6+
public int countDigits(int num) {
7+
final String number = num + "";
8+
int divisors = 0;
9+
for (int index = 0 ; index < number.length() ; index++) {
10+
int digit = number.charAt(index) - '0';
11+
if (num % digit == 0) divisors++;
12+
}
13+
return divisors;
14+
}
15+
}

0 commit comments

Comments
 (0)