Skip to content

Commit cd27feb

Browse files
committed
1108. Defanging an IP address
1 parent 78cce7a commit cd27feb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
--------------------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)