cs: add «2843. Count Symmetric Integers»
URL: https://leetcode.com/problems/count-symmetric-integers/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
e69372dbef
commit
aab8e6466e
1 changed files with 19 additions and 0 deletions
19
cs/count-symmetric-integers.cs
Normal file
19
cs/count-symmetric-integers.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
public class Solution {
|
||||
public int CountSymmetricIntegers(int low, int high) {
|
||||
var count = 0;
|
||||
|
||||
for (var x = low; x <= high; ++x) {
|
||||
if (x < 100 && x % 11 == 0) {
|
||||
++count;
|
||||
} else if (1000 <= x && x < 10000) {
|
||||
var left = x / 1000 + (x % 1000) / 100;
|
||||
var right = (x % 100) / 10 + x % 10;
|
||||
if (left == right) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue