Skip to content

Commit 4fb80c4

Browse files
1108. Defanging an IP Address .join()
Difficulty: Easy 62 / 62 test cases passed. Runtime: 64 ms Memory Usage: 13.9 MB
1 parent c5101c3 commit 4fb80c4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Given a valid (IPv4) IP address, return a defanged version of that IP address.
3+
A defanged IP address replaces every period "." with "[.]".
4+
5+
Example:
6+
Input: address = "1.1.1.1"
7+
Output: "1[.]1[.]1[.]1"
8+
9+
Constraints:
10+
- The given address is a valid IPv4 address.
11+
"""
12+
#Difficulty: Easy
13+
#62 / 62 test cases passed.
14+
#Runtime: 64 ms
15+
#Memory Usage: 13.9 MB
16+
17+
#Runtime: 64 ms, faster than 6.22% of Python3 online submissions for Defanging an IP Address.
18+
#Memory Usage: 13.9 MB, less than 100.00% of Python3 online submissions for Defanging an IP Address.
19+
20+
class Solution:
21+
def defangIPaddr(self, address: str) -> str:
22+
return '[.]'.join(address.split('.'))

0 commit comments

Comments
 (0)