Skip to content

Commit 4b0fa53

Browse files
authored
Create Count Symmetric Integers.java
1 parent b850056 commit 4b0fa53

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Easy/Count Symmetric Integers.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int countSymmetricIntegers(int low, int high) {
3+
int result = 0;
4+
for (int i = low; i <= high; i++) {
5+
String s = String.valueOf(i);
6+
int diff = 0;
7+
int n = s.length();
8+
for (int j = 0; j < n / 2; j++) {
9+
diff += s.charAt(j) - s.charAt(n - j - 1);
10+
}
11+
if (n % 2 == 0 && diff == 0) {
12+
result++;
13+
}
14+
}
15+
return result;
16+
}
17+
}

0 commit comments

Comments
 (0)