IT/코딩테스트
[Leetcode] 2843. Count Symmetric Integers
이주디
2023. 9. 3. 11:53
728x90
https://leetcode.com/problems/count-symmetric-integers/
class Solution:
def countSymmetricIntegers(self, low: int, high: int) -> int:
count = 0
for num in range(low, high+1):
n = str(num)
length = len(n)
if length % 2 == 1:
continue # if num is odd number continue
sum_left= 0
sum_right = 0
for i in range(len(n) // 2):
sum_left += int(n[i])
sum_right += int(n[length - i - 1])
if sum_left == sum_right:
count += 1
return count
728x90