Java 98.7% Faster SIMPLE Hashmap EXPLAIN
\nclass Solution {\n    public int numOfPairs(String[] nums, String target) {\n        // Using hashmap, idea from other discussion post\n        // first we pu
```\nclass Solution {\n    public int numOfPairs(String[] nums, String target) {\n        // Using hashmap, idea from other discussion post\n        // first we put the number and occurances into the map\n        Map<String, Integer> mapping = new HashMap<>();\n        \n        for (int i = 0; i<nums.length; i++) {\n            // Here we put the number into the map\n            // if key exists, update the value to be original + 1\n            // otherwise, makes the value equal to 0+1 = 1 (one occurance)\n            mapping.put(nums[i], mapping.getOrDefault(nums[i], 0)+1);\n        }\n        \n        int result = 0;\n        for (int i = 1; i < target.length(); i++) {\n            // We seperate the target into two substrings each time\n            // and check if both substrings are in the mapping\n            // notice that substring function is inclusive for start and exclusive for end\n            // i starts from 1 because substring(0, 0) will be "" and we won\'t have this\n            // key in our mapping.\n            String sub1 = target.substring(0, i);\n            String sub2 = target.substring(i, target.length());\n            \n            if (mapping.containsKey(sub1) && mapping.containsKey(sub2)) {\n                // found the pair, update our count\n                if (sub1.equals(sub2)) {\n                    // They are the same, so refers to the same key value pairs, thus we should\n                    // reduce the number of occurance by 1 to make sure we don\'t use\n                    // a number on the same position(index) twice.\n                    // For example, ["20", "20"], target = "2023"\n                    // the output should be 2*1 = 2 instead of 2*2 = 4.\n                    result += mapping.get(sub1) * (mapping.get(sub1)-1);\n                } else {\n                    // They are different, so just do times\n                    result += mapping.get(sub1) * mapping.get(sub2);\n                }\n            }\n        }\n        return result;\n    }\n}\n```
['Java']