Really clear Java code
\nclass Solution {\n    public List<String> ambiguousCoordinates(String S) {\n        S = S.substring(1, S.length() - 1);\n        List<String> result = new Lin
```\nclass Solution {\n    public List<String> ambiguousCoordinates(String S) {\n        S = S.substring(1, S.length() - 1);\n        List<String> result = new LinkedList<>();\n        for (int i = 1; i < S.length(); i++) {\n            List<String> left = allowed(S.substring(0, i));\n            List<String> right = allowed(S.substring(i));\n            for (String ls : left) {\n                for (String rs : right) {\n                    result.add("(" + ls + ", " + rs + ")");\n                }\n            }\n        }\n        return result;\n    }\n    private List<String> allowed(String s) {\n        int l = s.length();\n        char[] cs = s.toCharArray();\n        List<String> result = new LinkedList<>();\n        if (cs[0] == \'0\' && cs[l - 1] == \'0\') { // "0xxxx0" Invalid unless a single "0"\n            if (l == 1) {\n                result.add("0");\n            }\n            return result;\n        }\n        if (cs[0] == \'0\') { // "0xxxxx" The only valid result is "0.xxxxx"\n            result.add("0." + s.substring(1));\n            return result;\n        }\n        if (cs[l - 1] == \'0\') { // "xxxxx0" The only valid result is itself\n            result.add(s);\n            return result;\n        }\n        result.add(s); // Add itself\n        for (int i = 1; i < l; i++) { // "xxxx" -> "x.xxx", "xx.xx", "xxx.x"\n            result.add(s.substring(0, i) + \'.\' + s.substring(i));\n        }\n        return result;\n    }\n}\n```
[]