We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 395e844 commit 212bab1Copy full SHA for 212bab1
Restore IP Addresses/Restore_IP_Addresses.py
@@ -0,0 +1,23 @@
1
+# 44ms 79.66%
2
+class Solution:
3
+ def restoreIpAddresses(self, s):
4
+ """
5
+ :type s: str
6
+ :rtype: List[str]
7
8
+ res_list = []
9
+ def dfs(strs, temp_str):
10
+ if not strs or temp_str.count('.') is 4:
11
+ if not strs and temp_str.count('.') is 4:
12
+ res_list.append(temp_str)
13
+ return
14
+ if strs[0] is '0':
15
+ dfs(strs[1:], temp_str + '0.')
16
+ else:
17
+ dfs(strs[1:], temp_str + strs[:1] + '.')
18
+ if len(strs) >= 2:
19
+ dfs(strs[2:], temp_str + strs[:2] + '.')
20
+ if len(strs) >= 3 and '100' <= strs[:3] <= '255':
21
+ dfs(strs[3:], temp_str + strs[:3] + '.')
22
+ dfs(s, '')
23
+ return [strs[:-1] for strs in res_list]
0 commit comments