https://leetcode.com/problems/count-symmetric-integers/description/
Count Symmetric Integers - LeetCode
Can you solve this real interview question? Count Symmetric Integers - You are given two positive integers low and high. An integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of
leetcode.com
1 2 3 4 5 6 7 8 9 10 11 12 | class Solution: def countSymmetricIntegers(self, low: int, high: int) -> int: answer = 0 for num in range(low, high + 1): num = str(num) if len(num) % 2 == 0: left_sum = sum(map(int, num[:len(num)//2])) right_sum = sum(map(int, num[len(num)//2:])) if left_sum == right_sum: answer += 1 return answer | cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2500. Delete Greatest Value in Each Row (0) | 2024.01.07 |
---|---|
leetcode 2706. Buy Two Chocolates (0) | 2024.01.05 |
leetcode 2894. Divisible and Non-divisible Sums Difference (1) | 2024.01.05 |
leetcode 2974. Minimum Number Game (0) | 2024.01.05 |
leetcode 2643. Row With Maximum Ones (1) | 2024.01.02 |
댓글