[Java] 100% 2ms Fast, Simple, Explanation
This code runs in 2ms or sometimes 3ms.\n\nThe execution speed comes from converting the original String to a char[] array, then do all the testing and building
This code runs in 2ms or sometimes 3ms.\n\nThe execution speed comes from converting the original `String` to a `char[]` array, then do all the testing and building of any valid coordinate strings directly from the `char[]` array, without any slow substring creation.  The code works with comma and any decimal point positions that are indexes into the `char[]` array, without actually putting any comma character or decimal point character into the `char[]` array.  The index for the comma or any decimal point are the index of the character in the `char[]` array that they would appear before, but they are **never** inserted into the `char[]`.  The loops that provide the comma or decimal point indexes, *always* give valid positions.\n\nThe basic code structure it to try all possible comma positions.  For a comma position, check if the first number is a valid integer, and try all possible decimal point positions for the first number and check if the first number is a valid decimal point\'ed number for that decimal point position.  For all valid first numbers, check if the second number would be a valid integer, or try all decimal point positions in the second number.  If two valid numbers are found, then call a method to build the valid coordinate string and add it to the result list.\n\nIf useful, please up-vote.\n```\nclass Solution {\n    public List<String> ambiguousCoordinates(String s) {\n        char[] sc = s.toCharArray();\n        List<String> result = new ArrayList();\n        StringBuilder sb = new StringBuilder();\n        \n        // Loop through all possible index positions for the comma.\n        for (int commaPos = 2; commaPos < sc.length - 1; commaPos++) {\n            \n            // If first number if a valid integer without any decimal point.\n            if (isValidNum(sc, 1, commaPos - 1)) {\n                if (isValidNum(sc, commaPos, sc.length - 2))\n                    buildNums(result, sb, sc, 1, commaPos-1, 0, commaPos, sc.length-2, 0);\n                for (int dp2Idx = commaPos + 1; dp2Idx < sc.length - 1; dp2Idx++)\n                    if (isValidDPNum(sc, commaPos, sc.length - 2, dp2Idx))\n                        buildNums(result, sb, sc, 1, commaPos-1, 0, commaPos, sc.length-2, dp2Idx);\n            }\n            \n            // Check all possible decimal point positions for the first number.\n            for (int dp1Idx = 2; dp1Idx < commaPos; dp1Idx++) {\n                if (isValidDPNum(sc, 1, commaPos - 1, dp1Idx)) {\n                    if (isValidNum(sc, commaPos, sc.length - 2))\n                        buildNums(result, sb, sc, 1, commaPos-1, dp1Idx, commaPos, sc.length-2, 0);\n                    for (int dp2Idx = commaPos + 1; dp2Idx < sc.length - 1; dp2Idx++)\n                        if (isValidDPNum(sc, commaPos, sc.length - 2, dp2Idx))\n                            buildNums(result, sb, sc, 1, commaPos-1, dp1Idx, commaPos, sc.length-2, dp2Idx);\n                }\n            }\n        }\n        return result;\n    }\n    \n    \n    // Check if a number in the char[] array is a valid integer without any decimal point.\n    private boolean isValidNum(char[] sc, int startIdx, int lastIdx) {\n        if (sc[startIdx] == \'0\' && lastIdx - startIdx != 0)  return false;\n        return true;\n    }\n    \n    \n    // Check if a number in the char[] array is valid number with virtual decimal point at the specified index.\n    private boolean isValidDPNum(char[] sc, int startIdx, int lastIdx, int dpIdx) {\n        if ((sc[startIdx] == \'0\' && dpIdx - startIdx != 1) || sc[lastIdx] == \'0\')  return false;\n        return true;\n    }\n    \n    \n    // Build the result two number coordinate string and add to the List of results.\n    private void buildNums(List<String> result, StringBuilder sb, char[] sc, \n                            int start1Idx, int last1Idx, int dp1Idx, \n                            int start2Idx, int last2Idx, int dp2Idx) {\n        sb.setLength(0);\n        sb.append(\'(\');\n        if (dp1Idx == 0)\n            sb.append(sc, start1Idx, last1Idx - start1Idx + 1);\n        else\n            sb.append(sc, start1Idx, dp1Idx - start1Idx).append(\'.\').append(sc, dp1Idx, last1Idx - dp1Idx + 1);\n        sb.append(\',\').append(\' \');\n        if (dp2Idx == 0)\n            sb.append(sc, start2Idx, last2Idx - start2Idx + 1);\n        else\n            sb.append(sc, start2Idx, dp2Idx - start2Idx).append(\'.\').append(sc, dp2Idx, last2Idx - dp2Idx + 1);\n        sb.append(\')\');\n        result.add(sb.toString());\n    }\n}\n```
['Java']