java | map
Code\n\nclass Solution {\n    public int numOfPairs(String[] nums, String target) {\n        Map<String, Integer> map = new HashMap<>();\n        int cnt = 0;\n
# Code\n```\nclass Solution {\n    public int numOfPairs(String[] nums, String target) {\n        Map<String, Integer> map = new HashMap<>();\n        int cnt = 0;\n        for(String str : nums){\n            if(target.startsWith(str)){\n                String suffix = target.substring(str.length());\n                cnt += map.getOrDefault(suffix, 0);\n            }\n            if(target.endsWith(str)){\n                String prefix = target.substring(0, target.length() - str.length());\n                cnt += map.getOrDefault(prefix, 0);\n            }\n            map.put(str, map.getOrDefault(str, 0) + 1);\n        }\n        return cnt;\n    }\n}\n```
['Java']