Skip to content

Practice Defanging an IP Address

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1108
LeetCode Problem

Defanging an IP Address

Problem Statement

Given a valid (IPv4) IP address, return a defanged version of that IP address. A defanged IP address replaces every period "." with "[.]".

Source: Defanging an IP Address on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
address = "1.1.1.1"
Output
"1[.]1[.]1[.]1"

# Example 2

Input
address = "255.100.50.0"
Output
"255[.]100[.]50[.]0"

Constraints

The given address is a valid IPv4 address.

Related LeetCode Problems

Practice more problems similar to Defanging an IP Address.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.