1 Star 0 Fork 0

唐梓迅/leetcode题解

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
.LeetCode 816 966 Bytes
一键复制 编辑 原始数据 按行查看 历史
唐梓迅 提交于 2022-11-07 21:11 +08:00 . 模糊坐标
class Solution {
public:
vector<string> getPos(string s) {
vector<string> pos;
if (s[0] != '0' || s == "0") pos.push_back(s);
for (int p = 1; p < s.size(); ++p) {
if ((p != 1 && s[0] == '0') || s.back() == '0') continue;
pos.push_back(s.substr(0, p) + "." + s.substr(p));
}
return pos;
}
vector<string> ambiguousCoordinates(string s) {
int n = s.size() - 2;
vector<string> res;
s = s.substr(1, s.size() - 2);
for (int l = 1; l < n; ++l) {
vector<string> lt = getPos(s.substr(0, l));
if (lt.empty()) continue;
vector<string> rt = getPos(s.substr(l));
if (rt.empty()) continue;
for (auto& i : lt) {
for (auto& j : rt) {
res.push_back("(" + i + ", " + j + ")");
}
}
}
return res;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/Tang-CMer/leetcode-problem-solving.git
git@gitee.com:Tang-CMer/leetcode-problem-solving.git
Tang-CMer
leetcode-problem-solving
leetcode题解
master

搜索帮助