From 29f41716f971506a001e8eb369b3f62964b43e8e Mon Sep 17 00:00:00 2001 From: GitHubQAQ <31883473+GitHubQAQ@users.noreply.github.com> Date: Sat, 7 May 2022 10:12:58 +0800 Subject: [PATCH] =?UTF-8?q?Update=200093.=E5=A4=8D=E5=8E=9FIP=E5=9C=B0?= =?UTF-8?q?=E5=9D=80.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 优化C++版本剪枝 当字符串长度小于4时,无法组成正确的IP地址,直接返回。 关于判断是否为数字的部分,是否有必要(题目明确说明s仅由数字组成) [从解题角度可以删去,保留的话增加容错,个人意见] --- problems/0093.复原IP地址.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/0093.复原IP地址.md b/problems/0093.复原IP地址.md index 7910fc50..6401824b 100644 --- a/problems/0093.复原IP地址.md +++ b/problems/0093.复原IP地址.md @@ -227,7 +227,7 @@ private: public: vector restoreIpAddresses(string s) { result.clear(); - if (s.size() > 12) return result; // 算是剪枝了 + if (s.size() < 4 || s.size() > 12) return result; // 算是剪枝了 backtracking(s, 0, 0); return result; }