Skip to content

1108. Defanging an IP Address 👎

  • Time:
  • Space:
1
2
3
4
5
6
class Solution {
 public:
  string defangIPaddr(string address) {
    return regex_replace(address, regex("[.]"), "[.]");
  }
};
1
2
3
4
5
class Solution {
  public String defangIPaddr(String address) {
    return address.replace(".", "[.]");
  }
}
1
2
3
class Solution:
  def defangIPaddr(self, address: str) -> str:
    return address.replace('.', '[.]')