1
class Solution:
2
def validIPAddress(self, queryIP: str) -> str:
3
queryIP = queryIP.replace(".", ":")
4
ct = 0
5
for i in queryIP.split(":"):
6
if i != "":
7
ct += 1
8
if ct == 4:
9
for i in queryIP.split(":"):
10
if i == "":
11
return "Neither"
12
if i.isnumeric():
13
if len(i) > 1:
14
if i.count("0") == len(i) or int(i) > 255 or i[0] == "0":
15
return "Neither"
16
else:
17
return "Neither"
18
return "IPv4"
19
elif ct == 8:
20
a = ["a", "b", "c", "d", "e", "f", "A", "B", "C", "D", "E", "F"]
21
for i in queryIP.split(":"):
22
if i == "":
23
return "Neither"
24
if len(i) < 5:
25
for j in i:
26
if j not in a and j.isdigit() == False:
27
return "Neither"
28
else:
29
return "Neither"
30
return "IPv6"
31
else:
32
return "Neither"

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0