File tree 1 file changed +20
-3
lines changed
src/main/java/com/thealgorithms/maths 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 1
1
package com .thealgorithms .maths ;
2
2
3
+ /**
4
+ * A positive integer is considered uniform if all
5
+ * of its digits are equal. For example, 222 is uniform,
6
+ * while 223 is not.
7
+ * Given two positive integers a and b, determine the
8
+ * number of uniform integers between a and b.
9
+ */
3
10
public final class UniformNumbers {
4
-
5
11
// Private constructor to prevent instantiation of the utility class
6
12
private UniformNumbers () {
7
13
// Prevent instantiation
8
14
}
9
-
15
+ /**
16
+ * This function will find the number of uniform numbers
17
+ * from 1 to num
18
+ * @param num upper limit to find the uniform numbers
19
+ * @return the count of uniform numbers between 1 and num
20
+ */
10
21
public static int uniformNumbers (int num ) {
11
22
String numStr = Integer .toString (num );
12
23
int uniformCount = (numStr .length () - 1 ) * 9 ;
@@ -20,7 +31,13 @@ public static int uniformNumbers(int num) {
20
31
21
32
return uniformCount ;
22
33
}
23
-
34
+ /**
35
+ * This function will calculate the number of uniform numbers
36
+ * between a and b
37
+ * @param a lower bound of range
38
+ * @param b upper bound of range
39
+ * @return the count of uniform numbers between a and b
40
+ */
24
41
public static int countUniformIntegers (int a , int b ) {
25
42
if (b > a && b > 0 && a > 0 ) {
26
43
return uniformNumbers (b ) - uniformNumbers (a - 1 );
You can’t perform that action at this time.
0 commit comments