Skip to content

Commit c589f87

Browse files
committed
Runtime: 63 ms (Top 100.0%) | Memory: 45.35 MB (Top 75.0%)
1 parent e6e7697 commit c589f87

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Runtime: 63 ms (Top 100.0%) | Memory: 45.35 MB (Top 75.0%)
2+
3+
var ambiguousCoordinates = function(S) {
4+
let ans = [], xPoss
5+
const process = (str, xy) => {
6+
if (xy)
7+
for (let x of xPoss)
8+
ans.push(`(${x}, ${str})`)
9+
else xPoss.push(str)
10+
}
11+
const parse = (str, xy) => {
12+
if (str.length === 1 || str[0] !== "0")
13+
process(str, xy)
14+
if (str.length > 1 && str[str.length-1] !== "0")
15+
process(str.slice(0,1) + "." + str.slice(1), xy)
16+
if (str.length > 2 && str[0] !== "0" && str[str.length-1] !== "0")
17+
for (let i = 2; i < str.length; i++)
18+
process(str.slice(0,i) + "." + str.slice(i), xy)
19+
}
20+
for (let i = 2; i < S.length - 1; i++) {
21+
let strs = [S.slice(1,i), S.slice(i, S.length - 1)]
22+
xPoss = []
23+
for (let j = 0; j < 2; j++)
24+
if (xPoss.length || !j) parse(strs[j], j)
25+
}
26+
return ans
27+
};

0 commit comments

Comments
 (0)