aboutsummaryrefslogtreecommitdiff
path: root/defanging_ip_address.py
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-09-09 08:26:34 -0600
committerJack Sangdahl <[email protected]>2025-09-09 08:26:34 -0600
commitd782a5138b047c6ee14bded264a1af24fbcfcb4d (patch)
treeda7211c8c0c03ac7e7fd84574efddc4331613773 /defanging_ip_address.py
parentd17d14d45956ea9af8f75e23181d708e4f76979f (diff)
downloadleetcode-d782a5138b047c6ee14bded264a1af24fbcfcb4d.tar.gz
leetcode-d782a5138b047c6ee14bded264a1af24fbcfcb4d.zip
1108. defanging an ip address
Diffstat (limited to 'defanging_ip_address.py')
-rw-r--r--defanging_ip_address.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/defanging_ip_address.py b/defanging_ip_address.py
new file mode 100644
index 0000000..c9daae2
--- /dev/null
+++ b/defanging_ip_address.py
@@ -0,0 +1,22 @@
+# 1108. Defanging an IP Address
+from re import sub
+
+"""
+given a valid ipv4 'address', return a defanged version of that ip address. a
+defanged ip address replaces every period "." with '[.]'.
+"""
+
+
+class Solution(object):
+ def defangIPaddr(self, address):
+ """
+ :type address: str
+ :rtype: str
+ """
+ return sub("\.", "[.]", address)
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.defangIPaddr(address="1.1.1.1"))
+ print(obj.defangIPaddr(address="255.100.50.0"))