255. Defanging an IP Address

MediumStringString

Given a valid IPv4 address, return a defanged version where every period '.' is replaced with '[.]'.

Input: A quoted IPv4 address string.

Output: Quoted string — the defanged address.

Examples

Example 1
Input: "1.1.1.1"
Output: "1[.]1[.]1[.]1"
Explanation: All periods replaced.
Example 2
Input: "255.100.50.0"
Output: "255[.]100[.]50[.]0"
Explanation: Defanged.
Example 3
Input: "0.0.0.0"
Output: "0[.]0[.]0[.]0"
Explanation: All zeros.

Constraints

Asked by

MetaGoogleBloombergMicrosoftAmazon
Solve this problem in the editor →