Coding
Published on

Leetcode 1108 - Defanging an IP Address solution

Authors

Solution One:

class Solution:
    def defangIPaddr(self, address: str) -> str:
        return address.replace('.', '[.]')

Solution Two:

Using regex

class Solution {
    public String defangIPaddr(String address) {
        return address.replaceAll("\\.", "[.]");
    }
}