diff --git a/problems/0093.复原IP地址.md b/problems/0093.复原IP地址.md index 97178cd5..4e32af99 100644 --- a/problems/0093.复原IP地址.md +++ b/problems/0093.复原IP地址.md @@ -424,6 +424,30 @@ class Solution: return True ``` +python3; 简单拼接版本(类似Leetcode131写法): +```python +class Solution: + def restoreIpAddresses(self, s: str) -> List[str]: + global results, path + results = [] + path = [] + self.backtracking(s,0) + return results + + def backtracking(self,s,index): + global results,path + if index == len(s) and len(path)==4: + results.append('.'.join(path)) # 在连接时需要中间间隔符号的话就在''中间写上对应的间隔符 + return + for i in range(index,len(s)): + if len(path)>3: break # 剪枝 + temp = s[index:i+1] + if (int(temp)<256 and int(temp)>0 and temp[0]!='0') or (temp=='0'): + path.append(temp) + self.backtracking(s,i+1) + path.pop() +``` + ## Go ```go