Skip to content

Commit 194b800

Browse files
add 2843
1 parent d6ae066 commit 194b800

File tree

3 files changed

+58
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src

3 files changed

+58
-0
lines changed

paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
| 2859 | [Sum of Values at Indices With K Set Bits](https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2859.java) | | Easy |
1313
| 2855 | [Minimum Right Shifts to Sort the Array](https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2855.java) | | Easy |
1414
| 2848 | [Points That Intersect With Cars](https://leetcode.com/problems/points-that-intersect-with-cars/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2848.java) | | Easy |
15+
| 2843 | [Count Symmetric Integers](https://leetcode.com/problems/count-symmetric-integers/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2843.java) | | Easy |
1516
| 2839 | [Check if Strings Can be Made Equal With Operations I](https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2839.java) | | Easy |
1617
| 2833 | [Furthest Point From Origin](https://leetcode.com/problems/furthest-point-from-origin/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2833.java) | | Easy |
1718
| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2828.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
public class _2843 {
4+
public static class Solution1 {
5+
public int countSymmetricIntegers(int low, int high) {
6+
int ans = 0;
7+
for (int num = low; num <= high; num++) {
8+
ans += isSymmetric(num);
9+
}
10+
return ans;
11+
}
12+
13+
private int isSymmetric(int num) {
14+
String numStr = String.valueOf(num);
15+
if (numStr.length() % 2 != 0) {
16+
return 0;
17+
}
18+
int sum1 = 0;
19+
int sum2 = 0;
20+
for (int i = 0; i < numStr.length() / 2; i++) {
21+
sum1 += Integer.parseInt(numStr.charAt(i) + "");
22+
sum2 += Integer.parseInt(numStr.charAt(numStr.length() - i - 1) + "");
23+
}
24+
if (sum1 == sum2) {
25+
return 1;
26+
}
27+
return 0;
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.thirdthousand;
2+
3+
import com.fishercoder.solutions.thirdthousand._2843;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _2843Test {
10+
private static _2843.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _2843.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(9, solution1.countSymmetricIntegers(1, 100));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(9, solution1.countSymmetricIntegers(10, 100));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)