-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path93.py
More file actions
23 lines (21 loc) · 752 Bytes
/
Copy path93.py
File metadata and controls
23 lines (21 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
def restoreIpAddresses(self, s: str) -> List[str]:
n = len(s)
def Track(num, pos, str):
if pos == n and num < 4:
return
if num == 4:
if pos == n:
ret.append(str[:-1])
return
for i in range(3):
if pos + i >= n:
break
temp = s[pos: pos + i + 1]
if (int(temp) == 0 and len(temp) == 1) or (int(temp) > 0 and int(temp) <= 255 and temp[0] != '0'):
str += temp + '.'
Track(num + 1, pos + i + 1, str)
str = str[:-(len(temp) + 1)]
ret = []
Track(0, 0, "")
return ret