-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
28 lines (26 loc) · 927 Bytes
/
Solution.java
File metadata and controls
28 lines (26 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Solution {
public int countSymmetricIntegers(int low, int high) {
int count = 0;
for (int i = low; i <= high; i++) {
String s = String.valueOf(i);
if (s.length() % 2 == 0) {
int first = 0;
int last = 0;
for (int j = 0; j < s.length() / 2; j++) {
first += Character.getNumericValue(s.charAt(j));
last += Character.getNumericValue(s.charAt(s.length() - 1 - j));
}
if (first == last) {
count++;
}
}
}
return count;
}
// Main method to test
public static void main(String[] args) {
Solution sol = new Solution();
int result = sol.countSymmetricIntegers(1, 1000); // Try with any range
System.out.println("Symmetric integers count: " + result);
}
}