def isIp(ip_str): flag = True if '.' not in ip_str: return False if ip_str.count('.')!=3 : return False splitList = ip_str.split('.') for value in splitList: try: num = int(value) if num>=0 and num<=255: pass else: flag = False except: flag = False…
问题描述: Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example:Given "25525511135", return ["255.255.11.135", "255.255.111.35"]. (Order does not matter) 算法分析: 首先我们…
#!/usr/bin/python3 # -*- coding: utf-8 -*- import re ip = "192.168.1.1" ip = re.findall("^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|…