Skip to content

Commit 4546cb7

Browse files
committed
Modification Comment
1 parent 86609f6 commit 4546cb7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Defanging IP Address/EfficientSolution.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,25 @@
2020
#
2121
#Constraints:
2222
#
23-
#The given address is a valid IPv4 address.
23+
#The given address is a valid IPv4 address.
24+
class Solution:
25+
26+
def defangIPaddr(self, address):
27+
28+
string = [] #[]
29+
30+
for character in address:
31+
32+
if character == '.': #1.1.1.1 if . is in address
33+
34+
string.append("[.]") #we'll append it by ["[.]"]
35+
36+
else:
37+
38+
string.append(character) #Or we'll append it with characters
39+
40+
return "".join(string) #Finally we'll join the string which will give "1[.]1[.]1[.]1"
41+
.
42+
#Initialize empty string
43+
#For every character in our IP Address, we will check with the condition that if "." is in the address, we'll simply replace with our given value which is "[.]",
44+
#otherwise, we'll append remaining address. Lastly, we'll simply join all the character in string.

0 commit comments

Comments
 (0)