816. 模糊坐标
最后更新于
最后更新于
示例 1:
输入: "(123)"
输出: ["(1, 23)", "(12, 3)", "(1.2, 3)", "(1, 2.3)"]示例 2:
输入: "(00011)"
输出: ["(0.001, 1)", "(0, 0.011)"]
解释:
0.0, 00, 0001 或 00.01 是不被允许的。示例 3:
输入: "(0123)"
输出: ["(0, 123)", "(0, 12.3)", "(0, 1.23)", "(0.1, 23)", "(0.1, 2.3)", "(0.12, 3)"]func ambiguousCoordinates(s string) (ret []string) {
s = s[1:len(s)-1]
for i := 1; i < len(s); i++ {
xs, ys := search(s[:i]), search(s[i:])
for _, x := range xs {
for _, y := range ys {
ret = append(ret, fmt.Sprintf("(%s, %s)", x, y))
}
}
}
return
}
func search(s string) (ret []string) {
if s[0] != '0' || len(s) == 1 {
ret = append(ret, s)
}
for i := 1; i < len(s); i++ {
a, b := s[:i], s[i:]
if i != 1 && a[0] == '0' || b[len(b)-1] == '0' {
continue
}
ret = append(ret, a+"."+b)
}
return
}