2342. Max Sum of a Pair With Equal Sum of Digits

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2342

class Solution:
    def maximumSum(self, nums: List[int]) -> int:
        d = defaultdict(int)
        res = -1
        for v in nums:
            x, y = 0, v
            while y:
                x += y % 10
                y //= 10
            if x in d:
                res = max(res, d[x] + v)
            d[x] = max(d[x], v)
        return res