Merge pull request #1856 from ZerenZhang2022/patch-6

Update 0093.复原IP地址.md
This commit is contained in:
程序员Carl
2023-01-19 10:45:46 +08:00
committed by GitHub

View File

@ -427,6 +427,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