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
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 1978. Employees Whose Manager Left the Company (0) | 2023.09.05 |
---|---|
[Leetcode] 1075. Project Employees I (0) | 2023.09.04 |
[Leetcode] 1051. Height Checker (0) | 2023.09.02 |
[Leetcode] 88. Merge Sorted Array (1) | 2023.09.02 |
[Leetcode] 1089. Duplicate Zeros (0) | 2023.09.02 |