Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bcc1a20

Browse files
authoredApr 11, 2025··
Create 2843_Count_Symmetric_Integers.java
1 parent 33b32c7 commit bcc1a20

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
 
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Problem Number: 2843.
2+
3+
// Count Symmetric Integers.
4+
5+
class Solution {
6+
public int countSymmetricIntegers(int low, int high) {
7+
int ans = 0;
8+
9+
for (int num = low; num <= high; ++num)
10+
if (isSymmetricInteger(num))
11+
++ans;
12+
13+
return ans;
14+
}
15+
16+
private boolean isSymmetricInteger(int num) {
17+
if (num >= 10 && num <= 99)
18+
return num / 10 == num % 10;
19+
if (num >= 1000 && num <= 9999) {
20+
final int left = num / 100;
21+
final int right = num % 100;
22+
return left / 10 + left % 10 == right / 10 + right % 10;
23+
}
24+
return false;
25+
}
26+
}

0 commit comments

Comments
 (0)
Please sign in to comment.