✅Beginner Friendly (C++/Java/Python) Solution With Detailed Explanation✅
Intuition\nThe intuition is to find the number of pairs of strings in a given vector nums that, when concatenated in either order, match a target string.\n\n# A
# Intuition\nThe intuition is to find the number of pairs of strings in a given vector `nums` that, when concatenated in either order, match a target string.\n\n# Approach\n\n1. **Initialization**: The function starts by initializing `n` to the size of the input vector `nums` and `res` to 0, which will serve as the count of matching pairs.\n\n2. **Iterating Through Pairs**: It iterates through all possible pairs of strings within `nums` using two nested loops. The outer loop runs from the first element to the second-to-last element, and the inner loop runs from the element right after the current outer loop\'s index to the last element. This ensures every unique pair is considered without repetition.\n\n3. **Concatenation and Comparison**:\n   - For each pair `(nums[i], nums[j])`, the code first concatenates `nums[i]` and `nums[j]` and checks if the resulting string equals the target string. If it does, `res` is incremented.\n   - It then concatenates `nums[j]` and `nums[i]` (the reverse order) and checks if this equals the target string, incrementing `res` if so.\n\n4. **Return Result**: After all pairs have been considered, the function returns the total count of pairs (`res`) that match the target string when concatenated.\n\n\n# Complexity\n- **Time Complexity**: `O(n^2 * m)`, where `n` is the number of strings in the input vector `nums`, and `m` is the average length of the strings. The `n^2` term arises from the nested loops iterating over all pairs of strings. For each pair, concatenating the strings and comparing them to the target involves operations linear in the length of the strings, contributing the `m` factor.\n   \n- **Space Complexity**: `O(m)`, where `m` is the length of the longest string resulting from the concatenation of two strings in `nums` or the length of the `target` string, whichever is larger. This space is used when concatenating two strings and comparing them with the target. Note that the space used for the input (`nums` and `target`) is not considered part of the extra space for the algorithm.\n\n\n# Code\n```C++ []\nclass Solution {\npublic:\n    int numOfPairs(vector<string>& nums, string target) {\n        int n = nums.size();\n        int res = 0;\n        for (int i=0; i<n-1; i++)\n        {\n            for (int j=i+1; j<n; j++)\n            {\n                if (nums[i]+nums[j] == target)\n                    res++;\n\n                if (nums[j]+nums[i] == target)\n                    res++;\n            }\n        }\n\n        return res;\n    }\n};\n```\n```Java []\npublic class Solution {\n    public int numOfPairs(String[] nums, String target) {\n        int n = nums.length;\n        int res = 0;\n        for (int i = 0; i < n - 1; i++) {\n            for (int j = i + 1; j < n; j++) {\n                // Check if concatenating nums[i] and nums[j] equals the target\n                if (nums[i].concat(nums[j]).equals(target)) {\n                    res++;\n                }\n                \n                // Check if concatenating nums[j] and nums[i] equals the target\n                if (nums[j].concat(nums[i]).equals(target)) {\n                    res++;\n                }\n            }\n        }\n        return res;\n    }\n}\n\n```\n```Python []\nfrom typing import List\n\nclass Solution:\n    def numOfPairs(self, nums: List[str], target: str) -> int:\n        res = 0\n        n = len(nums)\n        for i in range(n-1):\n            for j in range(i+1, n):\n                # Check if concatenating nums[i] and nums[j] equals the target\n                if nums[i] + nums[j] == target:\n                    res += 1\n                # Check if concatenating nums[j] and nums[i] equals the target\n                if nums[j] + nums[i] == target:\n                    res += 1\n        return res\n\n```
['Array', 'String', 'C++', 'Java', 'Python3']