# LeetCode: 93. 复原IP地址¶

## 1、题目描述¶

输入: "25525511135"



## 2、解题思路¶

​ 先想到的是深度优先搜索

class Solution:
"""
:type s: str
:rtype: List[str]
"""

result = []
self.dfs(s, 0, [], result)
return list(set(result))

def dfs(self, s, index, current, result):
if index >= len(s):
if len(current) == 4:
result.append(".".join(current))
return
elif len(current) >= 4:
return

temp = current[:]
temp_num = int(s[index:index + 1])
if temp_num <= 255 and (len(s) - index - 1) <= (3 - len(current)) * 3:
temp.append(s[index:index + 1])
self.dfs(s, index + 1, temp, result)

temp = current[:]
temp_num = int(s[index:index + 2])
if temp_num <= 255 and s[index] != '0' and (len(s) - index - 2) <= (3 - len(current)) * 3:
temp.append(s[index:index + 2])
self.dfs(s, index + 2, temp, result)

temp = current[:]
temp_num = int(s[index:index + 3])
if temp_num <= 255 and s[index:index + 2] != '00' and s[index] != '0' and (len(s) - index - 3) <= (
3 - len(current)) * 3:
temp.append(s[index:index + 3])
self.dfs(s, index + 3, temp, result)