-
Notifications
You must be signed in to change notification settings - Fork 42
/
solution.js
41 lines (39 loc) · 1.01 KB
/
solution.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* @param {string} S
* @return {string[]}
*/
// 返回所有构成的子串
function helper (str) {
if (str[str.length - 1] === '0') {
return str.length > 1 && str[0] === '0' ? [] : [
str, ];
}
if (str[0] === '0') {
return [
str.length > 1 ? `0.${str.slice(1)}` : '0', ];
}
const result = [
str, ];
for (let i = 1; i < str.length; i++) {
result.push(`${str.slice(0, i)}.${str.slice(i)}`);
}
return result;
}
var ambiguousCoordinates = function (S) {
S = S.slice(1, -1);
const result = [];
for (let i = 1; i < S.length; i++) {
const A = helper(S.slice(0, i));
if (A.length > 0) {
const B = helper(S.slice(i));
if (B.length) {
for (let i = 0; i < A.length; i++) {
for (let j = 0; j < B.length; j++) {
result.push(`(${A[i]}, ${B[j]})`);
}
}
}
}
}
return result;
};