Apply a global string replacement from each dot to the required defanged token.
Complexity
O(n) time and O(n) output space.
Replace every period in an IPv4 address with a bracketed period.
Apply a global string replacement from each dot to the required defanged token.
O(n) time and O(n) output space.
package main
import "strings"
func defangIPaddr(address string) string { return strings.ReplaceAll(address, ".", "[.]") }
class Solution:
def defangIPaddr(self, address: str) -> str:
return address.replace(".", "[.]")
function defangIPaddr(address: string): string {
return address.replaceAll(".", "[.]");
}