File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ Problem: 1108. Defanging an IP Address
2
+
3
+ Given a valid (IPv4) IP address, return a defanged version of that IP address.
4
+ A defanged IP address replaces every period "." with "[.]".
5
+
6
+ Example 1:
7
+
8
+ Input: address = "1.1.1.1"
9
+ Output: "1[.]1[.]1[.]1"
10
+ Example 2:
11
+
12
+ Input: address = "255.100.50.0"
13
+ Output: "255[.]100[.]50[.]0"
14
+
15
+ Constraints: The given address is a valid IPv4 address.
16
+ --------------------------------------------------------------------------------------------------------------------------------------
17
+ Solution:
18
+
19
+ class Solution:
20
+ def defangIPaddr(self, address: str) -> str:
21
+ return address.replace('.', '[.]')
22
+
23
+ # Below are the 2 possible solutions
24
+ # return '[.]'.join(address.split('.'))
25
+ # return re.sub('\.', '[.]', address)
26
+ --------------------------------------------------------------------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments