## LeetCode 093 Restore IP Addresses Problem

``````class Solution(object):
#     """
#     :type s: str
#     :rtype: List[str]
#     """
#     ls = len(s)
#     if ls == 0 or ls > 12:
#         return []
#     if s == '0000':
#         return ['0.0.0.0']
#     return self.getremainIP(s, 0, 4)
#
# def getremainIP(self, s, pos, count):
#     if count == 1:
#         curr = s[pos:]
#         if self.isNum(curr):
#             return [curr]
#     result = []
#     for i in range(pos, pos + 3):
#         if i + 1 < len(s):
#             prefix = s[pos:i + 1]
#             if self.isNum(prefix):
#                 res = self.getremainIP(s, i + 1, count - 1)
#                 result.extend([prefix + '.' + t for t in res])
#     return result
#
# def isNum(self, prefix):
#     curr = int(prefix)
#     if curr > 255:
#         return False
#     if len(prefix) == 1:
#         return True
#     if prefix[0] == '0':
#         return False
#     return True

ls = len(s)
if ls == 0 or ls > 12:
return []
res = []
for i in range(1, 4):
for j in range(1, 4):
for k in range(1, 4):
m = ls - i - j - k
if m > 0 and m <= 3:
add3 = s[i + j:i + j + k]
add4 = s[i + j + k:]
return res

return True
return False
return True
return False

if __name__ == '__main__':
s = Solution()
# print s.longestValidParentheses(")(((((()())()()))()(()))(")