✅[Python] Math + Hash With Explanation⬆️🤩🔥⚡⬆️
\u2B06\uFE0F\uD83E\uDD29\uD83D\uDD25\u26A1\u2B06\uFE0F Up Vote If You Like My Answers \u2B06\uFE0F\uD83E\uDD29\uD83D\uDD25\u26A1\u2B06\uFE0F\n\nWe make a counte
**\u2B06\uFE0F\uD83E\uDD29\uD83D\uDD25\u26A1\u2B06\uFE0F Up Vote If You Like My Answers \u2B06\uFE0F\uD83E\uDD29\uD83D\uDD25\u26A1\u2B06\uFE0F**\n\nWe make a counter (HashMap that counts each element)of each str in nums, then we take the prefix and postfix statring from i = 1 until i=len(target)-1 (so we won\'t check the whole word), and check if they are in the counter.\n**If prefix==postfix** - we need to check that the counter is greater then 1, if so, we append using the formula:\n![image](https://assets.leetcode.com/users/images/ca2b05af-5c31-4d15-9968-e828f94a6f5c_1656343025.1779404.png)\nwhere n = counter[prefix] and k = 2.\n*For those who are not farmiliar with this formula :*\n*This is the formula for counting how many diffrent combination we have of taking k-element from the n-total, BUT until n C k, here the order matther, meaning that if you have two blue balls - let\'s say A,B then:\nn C k would be = 1 (because they are both blue so A,B = B,A)\nBut with this formula = 2 (because it will count A,B and B,A as two diffrent combinations).*\n**If prefix  != postfix** then we just append he multiplication of both counts.\n\n\n```\nclass Solution:\n    def numOfPairs(self, nums: List[str], target: str) -> int:\n        c = Counter(nums)\n        ans = 0\n        for i in range(1,len(target)):\n            if target[:i] in c and target[i:] in c:\n                if target[:i] == target[i:]:\n                    ans += (c[target[:i]] > 1) and math.factorial(c[target[:i]])//math.factorial(c[target[:i]]-2)\n                else:\n                    ans += c[target[:i]]*c[target[i:]]\n        return ans\n```
[]