All problems
1139EasyString

Wrapping the Dots of an Address

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1108Defanging an IP Address

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

The string address is a valid IPv4 address: four groups of decimal digits joined by single dots, as in 192.168.0.1.

Return the address with every dot swapped for the three characters [.].

Examples

Example 1

Input
address = "192.168.0.1"
Output
"192[.]168[.]0[.]1"

Each of the three dots becomes the bracketed form and the digit groups pass through untouched.

Example 2

Input
address = "0.0.0.0"
Output
"0[.]0[.]0[.]0"

All four groups are a single zero, and the three dots are wrapped just the same.

Example 3

Input
address = "12.34.56.78"
Output
"12[.]34[.]56[.]78"

Only the dots change, so all eight digits come through exactly as they were.

Constraints

  • address is a valid IPv4 address

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def defang_i_paddr(address: str) -> str:
Java
public String defangIPaddr(String address)
September 7
Apply