Python solutions from brute force O(nn)[accepted] to O(n) with Counter
solution 1:\nwe can burte force check if every pair of elements in nums can be form tagret,this will take O(nn) time with O(1) space\nsolution 2:\nbrute force i
**solution 1:**\nwe can burte force check if every pair of elements in nums can be form tagret,this will take O(nn) time with O(1) space\n**solution 2:**\nbrute force is trvial, if there are many duplicated elements will waste time,anther solution: split target into all possibles, check and count how many subparties can be formed from nums:\neg: taget="221" nums=[\'1,\'1\',\'2,\'2\',\'22\'],  possible splits: "221"="2"+"21"(but there\'s no \'21\', so it\'s not valid split), "221"="22"+"1"\nthere are 2 \'1\' and 1 \'22\' in nums so there are  2* 1 paires of the splits.\n\n\n```\nclass Solution(object):\n    def numOfPairs(self, nums, target):\n        """\n        :type nums: List[str]\n        :type target: str\n        :rtype: int\n        """\n        #sol1:brute force check\n        ans=0\n        for i in range(len(nums)):\n            fst=nums[i]\n            for j in range(len(nums)):\n                if i==j:continue\n                if fst+nums[j]==target:ans=ans+1\n        return ans\n```\n```\nclass Solution(object):\n    def numOfPairs(self, nums, target):\n        """\n        :type nums: List[str]\n        :type target: str\n        :rtype: int\n        """\n        #sol2 using Counter and iterative check\n        counter,ans=Counter(nums),0\n        for i in range(1,len(target)):\n            a,b=target[:i],target[i:]\n            if a not in counter or b not in counter:continue\n            ans=ans+counter[a]*counter[b] if a!=b else ans+counter[a]*(counter[a]-1)\n        return ans\n```\n\n\n
['Python']