We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 33b32c7 commit bcc1a20Copy full SHA for bcc1a20
JAVA/2843_Count_Symmetric_Integers.java
@@ -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