JAVA || HASHMAP
Better Solution:\n\nclass Solution {\n    public int numOfPairs(String[] nums, String target) {\n        Map<String, Integer> map = new HashMap<>();\n        fo
Better Solution:\n``` \nclass Solution {\n    public int numOfPairs(String[] nums, String target) {\n        Map<String, Integer> map = new HashMap<>();\n        for (String num : nums) {\n            map.put(num, 1 + map.getOrDefault(num, 0));\n        }\n        int res = 0;\n        for (String s : map.keySet()) {\n            if (target.startsWith(s)) {\n                if (target.equals(s + s)) {\n                    res += map.get(s) * (map.get(s) - 1);\n                } else if (map.containsKey(target.substring(s.length()))) {\n                    res += map.get(s) * map.get(target.substring(s.length()));\n                }\n            }\n        }\n        return res;\n    }\n}\n\n```\n\n\n```\nclass Solution {\n    \n    public boolean match(String s, String target, int ind){\n        // int tar = \n        if(ind == 0)\n            for(int i = ind ; i < s.length() && i<target.length() ; i++)\n                if(s.charAt(i) != target.charAt(i))\n                    return false;\n        int last = s.length()-1;\n        if(ind == target.length()-1)\n            for(int i = ind ; last>=0 &&  i>=0 ; i--)\n                if(s.charAt(last--) != target.charAt(i))\n                    return false;\n        return true;\n        \n    }\n        \n    public int numOfPairs(String[] nums, String target) {\n        int ans = 0;\n        HashMap<String,Integer> hm = new HashMap<>();\n        for(String s: nums){\n            boolean front = match(s, target, 0);\n            boolean back = match(s, target, target.length()-1);\n            if(front){\n//                 s is the front of target\n                String part ="";\n                for(int i = s.length() ; i < target.length() ; i++)\n                    part+=target.charAt(i);\n                \n                if(hm.containsKey(part))\n                    ans+=hm.get(part);\n            }\n            if(back){\n//                 s is the back of target\n                String part ="";\n                for(int i = 0 ; i < target.length()-s.length() ; i++)\n                    part+=target.charAt(i);\n                \n                if(hm.containsKey(part))\n                    ans+=hm.get(part);\n            }\n            hm.put(s, hm.getOrDefault(s,0)+1);\n            \n        }\n        return ans;\n    }\n}\n```
['Java']