代码拉取完成,页面将自动刷新
# Time: O(1)
# Space: O(1)
import string
class Solution(object):
def validIPAddress(self, IP):
"""
:type IP: str
:rtype: str
"""
blocks = IP.split('.')
if len(blocks) == 4:
for i in xrange(len(blocks)):
if not blocks[i].isdigit() or not 0 <= int(blocks[i]) < 256 or \
(blocks[i][0] == '0' and len(blocks[i]) > 1):
return "Neither"
return "IPv4"
blocks = IP.split(':')
if len(blocks) == 8:
for i in xrange(len(blocks)):
if not (1 <= len(blocks[i]) <= 4) or \
not all(c in string.hexdigits for c in blocks[i]):
return "Neither"
return "IPv6"
return "Neither"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。