题解:
- 暴力枚举 两个点
- 判断小数点前 是否 有前导零, 判断小数点后 是否 有后置0
class Solution {
public List<String> ambiguousCoordinates(String s) {
s = s.substring(1, s.length() - 1);
List<String> res = new ArrayList<>();
for (int i = 1; i < s.length(); i++) {
List<String> x = get(s.substring(0, i));
List<String> y = get(s.substring(i));
for (String x1 : x) {
for (String s1 : y) {
res.add("(" + x1 + ", " + s1 + ")");
}
}
}
return res;
}
public List<String> get(String s) {
List<String> res = new ArrayList<>();
if (s.length() == 1 || s.charAt(0) != '0') res.add(s);
for (int i = 1; i < s.length(); i++) {
String a = s.substring(0, i);
String b = s.substring(i);
if (a.length() > 1 && a.charAt(0) == (int)'0') continue;
if (b.charAt(b.length() - 1) == (int)'0') continue;
res.add(a + "." + b);
}
return res;
}
}
标签:String,int,res,模糊,List,substring,length,坐标,816
From: https://www.cnblogs.com/eiffelzero/p/16867912.html