2023. Number of Pairs of Strings With Concatenation Equal to Target

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

Содержание

LeetCode problem 2023

class Solution:
    def numOfPairs(self, nums: List[str], target: str) -> int:
        cnt = Counter(nums)
        res = 0
        for i in range(1, len(target)):
            a, b = target[:i], target[i:]
            if a != b:
                res += cnt[a] * cnt[b]
            else:
                res += cnt[a] * (cnt[a] - 1)
        return res